-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
37 lines (31 loc) · 990 Bytes
/
app.py
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
from flask import Flask, request, jsonify, render_template
from flask_cors import CORS
from chatbot import chatCevapAl, kaydetSoruCevap
import os
env = os.environ.get('ENVIRONMENT', 'development')
app = Flask(__name__)
CORS(app)
@app.route('/')
def frontendIndex():
return render_template(
'index.html',
logo_image="/static/images/chatcbr3.png",
name="ChatCBR"
)
@app.route("/api/sor")
def soruSor():
soru = request.args.get("soru")
if not soru:
return jsonify({"ok": False, "message": "Soru girmediniz."})
try:
cevap = chatCevapAl(soru)
if cevap is None:
return jsonify({"ok": False, "message": "Cevap alınamadı."})
else:
# Soru ve cevabı MongoDB'ye kaydet
kaydetSoruCevap(soru, cevap)
return jsonify({"ok": True, "cevap": cevap})
except Exception as e:
return jsonify({"ok": False, "message": str(e)})
if __name__ == "__main__":
app.run()