Mubbashir Ahmed
commited on
Commit
·
de5f14a
1
Parent(s):
612686d
reverting back
Browse files
app.py
CHANGED
@@ -32,31 +32,6 @@ model_list = {
|
|
32 |
}
|
33 |
}
|
34 |
|
35 |
-
# ------------------------
|
36 |
-
# Prompt Construction
|
37 |
-
# ------------------------
|
38 |
-
FEW_SHOT = """Q: Show all department names.
|
39 |
-
A: SELECT name FROM department;
|
40 |
-
|
41 |
-
Q: Count number of students.
|
42 |
-
A: SELECT COUNT(*) FROM student;
|
43 |
-
"""
|
44 |
-
|
45 |
-
def build_prompt(user_question):
|
46 |
-
return f"""You are an expert SQL assistant. Convert the given question into a valid SQL query.
|
47 |
-
|
48 |
-
Instructions:
|
49 |
-
- Return only the SQL query.
|
50 |
-
- Do not include markdown, explanations, or formatting.
|
51 |
-
- Follow Spider dataset SQL syntax.
|
52 |
-
|
53 |
-
Examples:
|
54 |
-
{FEW_SHOT}
|
55 |
-
|
56 |
-
Now answer this:
|
57 |
-
Q: {user_question}
|
58 |
-
A:"""
|
59 |
-
|
60 |
# ------------------------
|
61 |
# Inference + Evaluation Logic
|
62 |
# ------------------------
|
@@ -68,16 +43,15 @@ def evaluate_all_models(user_input, expected_sql, chat_history):
|
|
68 |
client = model_config["client"]
|
69 |
model_id = model_config["model_id"]
|
70 |
|
71 |
-
|
72 |
-
messages = [{"role": "user", "content": prompt}]
|
73 |
-
|
74 |
try:
|
75 |
start_time = time.time()
|
|
|
76 |
result = client.chat.completions.create(
|
77 |
model=model_id,
|
78 |
messages=messages
|
79 |
)
|
80 |
-
model_sql = result.choices[0].message.content
|
81 |
latency = int((time.time() - start_time) * 1000)
|
82 |
|
83 |
except Exception as e:
|
@@ -116,7 +90,7 @@ def get_random_spider_prompt():
|
|
116 |
# Gradio UI
|
117 |
# ------------------------
|
118 |
with gr.Blocks() as demo:
|
119 |
-
gr.Markdown("## 🧠 Spider Dataset Model Evaluation
|
120 |
|
121 |
prompt_input = gr.Textbox(label="Your Prompt", lines=3, placeholder="Ask your BI question...")
|
122 |
expected_sql_display = gr.Textbox(label="Expected SQL", lines=2, interactive=False)
|
@@ -142,6 +116,5 @@ with gr.Blocks() as demo:
|
|
142 |
outputs=[chat_display, chat_memory, evaluation_display]
|
143 |
)
|
144 |
|
145 |
-
|
146 |
# Launch
|
147 |
demo.launch()
|
|
|
32 |
}
|
33 |
}
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
# ------------------------
|
36 |
# Inference + Evaluation Logic
|
37 |
# ------------------------
|
|
|
43 |
client = model_config["client"]
|
44 |
model_id = model_config["model_id"]
|
45 |
|
46 |
+
messages = chat_history + [{"role": "user", "content": user_input}]
|
|
|
|
|
47 |
try:
|
48 |
start_time = time.time()
|
49 |
+
|
50 |
result = client.chat.completions.create(
|
51 |
model=model_id,
|
52 |
messages=messages
|
53 |
)
|
54 |
+
model_sql = result.choices[0].message.content
|
55 |
latency = int((time.time() - start_time) * 1000)
|
56 |
|
57 |
except Exception as e:
|
|
|
90 |
# Gradio UI
|
91 |
# ------------------------
|
92 |
with gr.Blocks() as demo:
|
93 |
+
gr.Markdown("## 🧠 Spider Dataset Model Evaluation")
|
94 |
|
95 |
prompt_input = gr.Textbox(label="Your Prompt", lines=3, placeholder="Ask your BI question...")
|
96 |
expected_sql_display = gr.Textbox(label="Expected SQL", lines=2, interactive=False)
|
|
|
116 |
outputs=[chat_display, chat_memory, evaluation_display]
|
117 |
)
|
118 |
|
|
|
119 |
# Launch
|
120 |
demo.launch()
|