salience-editor/api/salience/__init__.py

30 lines
828 B
Python
Raw Normal View History

2025-10-30 16:26:48 -07:00
from flask import Flask, request
import numpy as np
2025-10-30 16:26:48 -07:00
from .salience import extract, AVAILABLE_MODELS
import json
app = Flask(__name__)
with open('./transcript.txt', 'r') as file:
source_text = file.read().strip()
2025-10-30 16:26:48 -07:00
@app.route("/models")
def models_view():
return json.dumps(list(AVAILABLE_MODELS.keys()))
@app.route("/salience")
def salience_view():
2025-10-30 16:26:48 -07:00
model_name = request.args.get('model', 'all-mpnet-base-v2')
# Validate model name
if model_name not in AVAILABLE_MODELS:
return json.dumps({'error': f'Invalid model: {model_name}'}), 400
sentence_ranges, adjacency = extract(source_text, model_name)
return json.dumps({
'source': source_text,
'intervals': sentence_ranges,
'adjacency': np.nan_to_num(adjacency.numpy()).tolist(),
2025-10-30 16:26:48 -07:00
'model': model_name,
})