Spaces:
Running
Running
Commit
·
f093679
1
Parent(s):
7795384
feat: add main menu options and scripts
Browse files- app.py +82 -24
- resources/ai_app.db +0 -0
app.py
CHANGED
@@ -173,6 +173,22 @@ def examples():
|
|
173 |
example_tabs = st.tabs([f"Example {i+1}" for i in range(len(example_df))])
|
174 |
example_btns = []
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
for idx, row in example_df.iterrows():
|
177 |
with example_tabs[idx]:
|
178 |
st.markdown("##### Context:")
|
@@ -184,26 +200,39 @@ def examples():
|
|
184 |
|
185 |
if example_btns[idx]:
|
186 |
st.markdown("##### SQL query:")
|
187 |
-
tries =
|
188 |
with st.spinner("Generating SQL query..."):
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
start_time = time.time()
|
191 |
query = ask_text2sql(row["question"], row["context"])
|
192 |
end_time = time.time()
|
193 |
-
st.
|
194 |
-
"The SQL query generated by the model in {:.2f}s is:".format(
|
195 |
end_time - start_time
|
196 |
)
|
197 |
)
|
198 |
st.code(format_sql(query), language="sql")
|
199 |
-
result = execute_sql(query)
|
200 |
-
|
201 |
-
st.write("Executing the SQL query yields the following result:")
|
202 |
-
st.dataframe(pd.DataFrame(result), hide_index=True)
|
203 |
-
if result is not None:
|
204 |
-
break
|
205 |
-
else:
|
206 |
-
tries -= 1
|
207 |
|
208 |
|
209 |
# Define a function for the Stock Prediction page
|
@@ -233,28 +262,57 @@ CREATE TABLE product (id number, category text, name text, description text, pri
|
|
233 |
)
|
234 |
get_sql_button = st.button("Generate SQL query")
|
235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
if get_sql_button:
|
237 |
st.markdown("##### Output")
|
238 |
-
tries =
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
start_time = time.time()
|
241 |
query = ask_text2sql(question, context)
|
242 |
end_time = time.time()
|
243 |
|
244 |
-
st.
|
245 |
-
"The SQL query generated by the model in {:.2f}s is:".format(
|
246 |
end_time - start_time
|
247 |
)
|
248 |
)
|
249 |
# Display the SQL query in a code block
|
250 |
st.code(format_sql(query), language="sql")
|
251 |
-
result = execute_sql(query)
|
252 |
-
st.write("Executing the SQL query yields the following result:")
|
253 |
-
st.dataframe(pd.DataFrame(result), hide_index=True)
|
254 |
-
if result is not None:
|
255 |
-
break
|
256 |
-
else:
|
257 |
-
tries -= 1
|
258 |
|
259 |
|
260 |
# Define a function for the About page
|
@@ -330,7 +388,7 @@ def references():
|
|
330 |
st.sidebar.title("Menu")
|
331 |
pages = [
|
332 |
"Introduction",
|
333 |
-
"Datasets",
|
334 |
"Examples",
|
335 |
"Interactive Demo",
|
336 |
"About",
|
|
|
173 |
example_tabs = st.tabs([f"Example {i+1}" for i in range(len(example_df))])
|
174 |
example_btns = []
|
175 |
|
176 |
+
with st.sidebar:
|
177 |
+
# create a blank space
|
178 |
+
st.write("")
|
179 |
+
st.write("")
|
180 |
+
st.write("")
|
181 |
+
execute_sql_query = st.checkbox(
|
182 |
+
"Execute SQL query",
|
183 |
+
)
|
184 |
+
num_tries = st.number_input(
|
185 |
+
"Number of tries",
|
186 |
+
value=3,
|
187 |
+
min_value=1,
|
188 |
+
max_value=10,
|
189 |
+
step=1,
|
190 |
+
)
|
191 |
+
|
192 |
for idx, row in example_df.iterrows():
|
193 |
with example_tabs[idx]:
|
194 |
st.markdown("##### Context:")
|
|
|
200 |
|
201 |
if example_btns[idx]:
|
202 |
st.markdown("##### SQL query:")
|
203 |
+
tries = num_tries
|
204 |
with st.spinner("Generating SQL query..."):
|
205 |
+
if execute_sql_query:
|
206 |
+
while tries > 0:
|
207 |
+
start_time = time.time()
|
208 |
+
query = ask_text2sql(row["question"], row["context"])
|
209 |
+
end_time = time.time()
|
210 |
+
st.write(
|
211 |
+
"The SQL query generated by the model in **{:.2f}s** is:".format(
|
212 |
+
end_time - start_time
|
213 |
+
)
|
214 |
+
)
|
215 |
+
st.code(format_sql(query), language="sql")
|
216 |
+
result = execute_sql(query)
|
217 |
+
|
218 |
+
st.write(
|
219 |
+
"Executing the SQL query yields the following result:"
|
220 |
+
)
|
221 |
+
st.dataframe(pd.DataFrame(result), hide_index=True)
|
222 |
+
if result is not None:
|
223 |
+
break
|
224 |
+
else:
|
225 |
+
tries -= 1
|
226 |
+
else:
|
227 |
start_time = time.time()
|
228 |
query = ask_text2sql(row["question"], row["context"])
|
229 |
end_time = time.time()
|
230 |
+
st.markdown(
|
231 |
+
"The SQL query generated by the model in **{:.2f}s** is:".format(
|
232 |
end_time - start_time
|
233 |
)
|
234 |
)
|
235 |
st.code(format_sql(query), language="sql")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
|
238 |
# Define a function for the Stock Prediction page
|
|
|
262 |
)
|
263 |
get_sql_button = st.button("Generate SQL query")
|
264 |
|
265 |
+
with st.sidebar:
|
266 |
+
# create a blank space
|
267 |
+
st.write("")
|
268 |
+
st.write("")
|
269 |
+
st.write("")
|
270 |
+
execute_sql_query = st.checkbox(
|
271 |
+
"Execute SQL query",
|
272 |
+
)
|
273 |
+
num_tries = st.number_input(
|
274 |
+
"Number of tries",
|
275 |
+
value=3,
|
276 |
+
min_value=1,
|
277 |
+
max_value=10,
|
278 |
+
step=1,
|
279 |
+
)
|
280 |
+
|
281 |
if get_sql_button:
|
282 |
st.markdown("##### Output")
|
283 |
+
tries = num_tries
|
284 |
+
if execute_sql_query:
|
285 |
+
while tries > 0:
|
286 |
+
start_time = time.time()
|
287 |
+
query = ask_text2sql(question, context)
|
288 |
+
end_time = time.time()
|
289 |
+
|
290 |
+
st.write(
|
291 |
+
"The SQL query generated by the model in **{:.2f}s** is:".format(
|
292 |
+
end_time - start_time
|
293 |
+
)
|
294 |
+
)
|
295 |
+
# Display the SQL query in a code block
|
296 |
+
st.code(format_sql(query), language="sql")
|
297 |
+
result = execute_sql(query)
|
298 |
+
st.write("Executing the SQL query yields the following result:")
|
299 |
+
st.dataframe(pd.DataFrame(result), hide_index=True)
|
300 |
+
if result is not None:
|
301 |
+
break
|
302 |
+
else:
|
303 |
+
tries -= 1
|
304 |
+
else:
|
305 |
start_time = time.time()
|
306 |
query = ask_text2sql(question, context)
|
307 |
end_time = time.time()
|
308 |
|
309 |
+
st.markdown(
|
310 |
+
"The SQL query generated by the model in **{:.2f}s** is:".format(
|
311 |
end_time - start_time
|
312 |
)
|
313 |
)
|
314 |
# Display the SQL query in a code block
|
315 |
st.code(format_sql(query), language="sql")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
|
318 |
# Define a function for the About page
|
|
|
388 |
st.sidebar.title("Menu")
|
389 |
pages = [
|
390 |
"Introduction",
|
391 |
+
# "Datasets",
|
392 |
"Examples",
|
393 |
"Interactive Demo",
|
394 |
"About",
|
resources/ai_app.db
CHANGED
Binary files a/resources/ai_app.db and b/resources/ai_app.db differ
|
|