Upload app (1).py
Browse files- app (1).py +45 -0
app (1).py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import os
|
3 |
+
from flask import Flask, request, jsonify
|
4 |
+
from flask_cors import CORS
|
5 |
+
|
6 |
+
# This is done in the Dockerfile now, but leaving for local dev consistency
|
7 |
+
os.environ["XDG_CACHE_HOME"] = os.environ.get("XDG_CACHE_HOME", "/tmp/.cache")
|
8 |
+
|
9 |
+
# Import handlers from other server files
|
10 |
+
from whisper_server import handle_transcribe, model as whisper_model
|
11 |
+
from qgen_server import handle_generate_questions, qg_model
|
12 |
+
from qamatcher_server import handle_match_question, matcher_model
|
13 |
+
|
14 |
+
app = Flask(__name__)
|
15 |
+
|
16 |
+
# Configure CORS to allow all origins
|
17 |
+
CORS(app, resources={r"/*": {"origins": "*"}})
|
18 |
+
|
19 |
+
@app.route('/')
|
20 |
+
def index():
|
21 |
+
return jsonify({
|
22 |
+
'message': 'VoiceQ AI Server is running!',
|
23 |
+
'models_loaded': {
|
24 |
+
'whisper': whisper_model is not None,
|
25 |
+
'question-generator': qg_model is not None,
|
26 |
+
'question-matcher': matcher_model is not None,
|
27 |
+
}
|
28 |
+
})
|
29 |
+
|
30 |
+
@app.route('/transcribe', methods=['POST'])
|
31 |
+
def transcribe():
|
32 |
+
return handle_transcribe()
|
33 |
+
|
34 |
+
@app.route('/generate-questions', methods=['POST'])
|
35 |
+
def generate_questions():
|
36 |
+
return handle_generate_questions()
|
37 |
+
|
38 |
+
@app.route('/match-question', methods=['POST'])
|
39 |
+
def match_question():
|
40 |
+
return handle_match_question()
|
41 |
+
|
42 |
+
# The following block is for local development only and will not be used in the Docker container.
|
43 |
+
if __name__ == '__main__':
|
44 |
+
PORT = int(os.environ.get("PORT", 5001))
|
45 |
+
app.run(host='0.0.0.0', port=PORT, debug=True)
|