-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (29 loc) · 866 Bytes
/
app.py
File metadata and controls
39 lines (29 loc) · 866 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
31
32
33
34
35
36
37
38
from flask import Flask, render_template, request, jsonify
from LLM_SQL import ask_llm
from db import *
import json
app = Flask(__name__)
# Initialize database on startup
init_db()
fill_db()
@app.route("/")
def index():
return render_template("index.html")
@app.route("/message", methods=["POST"])
def message():
data = request.get_json()
user_message = data.get("message", "")
# Simple placeholder logic
#reply = f"You said: {user_message}"
try:
llm_query = ask_llm(user_message)
if 'restricted' in llm_query:
answer = llm_query
else:
results = query_db(llm_query)
answer = json.dumps(results, indent=2)
except:
answer = "There was an error. Please try again."
return jsonify({"reply": answer})
if __name__ == "__main__":
app.run(debug=False)