-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (69 loc) · 2.15 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import openai
from flask import Flask, redirect, render_template, request, url_for
from flask_bootstrap import Bootstrap
from pymongo import MongoClient
import pandas as pd
import yaml
from Persona import Persona
from Connector import Connector, write_yaml
app = Flask(__name__)
openai.api_key = os.getenv("OPENAI_API_KEY")
@app.route("/")
def welcome():
return render_template(
"index.html",
)
@app.route("/chat", methods=["GET", "POST"])
def table():
db = 'chinook'
interpreter = Persona("interpreter")
model = 'gpt-3.5-turbo'
if request.method == "POST":
question = request.form["question"]
messages = interpreter.construct_messages(db, question)
response = openai.ChatCompletion.create(
model=model,
# temperature=0.6,
messages = messages
)
return redirect(url_for("table", result=response.choices[0].message.content))
query = request.args.get("result")
data = [{"": 0}]
if query != "":
con = Connector(db)
print(query)
data = con.query_SQLite(query)
print(data)
df = pd.DataFrame(data)
table = df.to_html(index=False)
return render_template(
"chat.html",
table = table,
query = query
)
@app.route('/semantics', methods=["GET", "POST"])
def semantics():
if request.method == 'POST':
# Process the form data
name = request.form['name']
table = request.form['table']
calculation = request.form['calculation']
dimensions = request.form['dimensions']
# Save the data to the database
data = {
'metric': {
'name': name,
'table': table,
'calculation': calculation,
'dimensions': dimensions
}
}
filename = "semantics/test.yaml"
write_yaml(data, filename)
# Redirect to a success page or perform any other action
return render_template('saved.html')
return render_template('semantics.html')
@app.route('/sources')
def sources():
return render_template('sources.html')