-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (43 loc) · 1.62 KB
/
app.py
File metadata and controls
58 lines (43 loc) · 1.62 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, request, jsonify, send_from_directory
from model.ask_question import ask_question, chat
app = Flask(__name__, static_folder='static', static_url_path='')
@app.route('/api/ask_stage1', methods=['POST'])
def handle_question_stage1():
data = request.get_json()
question = data.get('question', '')
if not question:
return jsonify({'error': 'Soru boş olamaz'}), 400
try:
answer = ask_question(user_q=question, stage=1)
return jsonify({'answer': answer})
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/api/ask_stage2', methods=['POST'])
def handle_question_stage2():
data = request.get_json()
question = data.get('question', '')
if not question:
return jsonify({'error': 'Soru boş olamaz'}), 400
try:
answer = ask_question(user_q=question, stage=2)
return jsonify({'answer': answer})
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/api/chat', methods=['POST'])
def handle_chat():
data = request.get_json()
question = data.get('question', '')
if not question:
return jsonify({'error': 'Soru boş olamaz'}), 400
try:
answer = chat(user_q=question)
return jsonify({'answer': answer})
except Exception as e:
return jsonify({'error': str(e)}), 500
# --- Statik dosyaları (HTML, CSS, JS) servis et ---
@app.route('/', defaults={'path': 'index.html'})
@app.route('/<path:path>')
def serve_static(path):
return send_from_directory(app.static_folder, path)
if __name__ == '__main__':
app.run(debug=True, port=5000)