-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (26 loc) · 963 Bytes
/
app.py
File metadata and controls
30 lines (26 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from flask import Flask, render_template, request, jsonify
from converter import convert_text_to_ts, detect_language
from ollama_client import ollama_request, ollama_convert_prompt
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/convert', methods=['POST'])
def convert():
data = request.form or request.json or {}
src = data.get('source', '')
prefer_ollama = data.get('use_ollama', 'false') in ('true', True, 'on')
language = detect_language(src)
# first try deterministic conversion
ts = convert_text_to_ts(src)
# if user asked for ollama fallback, use it
if prefer_ollama:
prompt = ollama_convert_prompt(src, language)
res = ollama_request(prompt)
if res:
ts = res
return jsonify({'ts': ts})
if __name__ == '__main__':
host = os.environ.get('FLASK_HOST', '127.0.0.1')
app.run(debug=True, host=host, port=5000)