Spaces:
Running
Running
use API access instaed of downloding the model
Browse files
app.py
CHANGED
@@ -2,25 +2,58 @@ import streamlit as st
|
|
2 |
from pipeline import text_to_sql
|
3 |
|
4 |
st.title("SQLCoder Text-to-SQL App")
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
with st.spinner("Generating SQL and executing query..."):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
st.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
else:
|
26 |
-
st.
|
|
|
2 |
from pipeline import text_to_sql
|
3 |
|
4 |
st.title("SQLCoder Text-to-SQL App")
|
5 |
+
st.write("Powered by defog/sqlcoder-7b-2 π")
|
6 |
|
7 |
+
# Sample queries for user guidance
|
8 |
+
st.sidebar.header("Sample Queries")
|
9 |
+
sample_queries = [
|
10 |
+
"List 11 names of ships type schooner",
|
11 |
+
"Show me the 5 oldest ships",
|
12 |
+
"What are the different types of vessels?",
|
13 |
+
"Count the number of ships by type",
|
14 |
+
"Show ships built after 1900"
|
15 |
+
]
|
16 |
|
17 |
+
selected_sample = st.sidebar.selectbox("Choose a sample query:", [""] + sample_queries)
|
18 |
+
|
19 |
+
# Main input
|
20 |
+
nl_query = st.text_input(
|
21 |
+
"Enter your natural language query:",
|
22 |
+
value=selected_sample if selected_sample else "List 11 names of ships type schooner",
|
23 |
+
help="Ask questions about your database in plain English"
|
24 |
+
)
|
25 |
+
|
26 |
+
if st.button("π Generate & Execute SQL"):
|
27 |
+
if nl_query.strip():
|
28 |
with st.spinner("Generating SQL and executing query..."):
|
29 |
+
try:
|
30 |
+
sql, results = text_to_sql(nl_query)
|
31 |
+
|
32 |
+
# Display results
|
33 |
+
st.success("Query executed successfully!")
|
34 |
+
|
35 |
+
# Show generated SQL
|
36 |
+
st.subheader("Generated SQL:")
|
37 |
+
st.code(sql, language="sql")
|
38 |
+
|
39 |
+
# Show results
|
40 |
+
st.subheader("Results:")
|
41 |
+
if results:
|
42 |
+
# Convert results to a more readable format
|
43 |
+
if isinstance(results[0], tuple):
|
44 |
+
# If results are tuples, display as table
|
45 |
+
st.write(f"Found {len(results)} rows:")
|
46 |
+
for i, row in enumerate(results[:50]): # Show first 50 rows
|
47 |
+
st.write(f"Row {i+1}: {row}")
|
48 |
+
if len(results) > 50:
|
49 |
+
st.info(f"Showing first 50 rows out of {len(results)} total results.")
|
50 |
+
else:
|
51 |
+
st.write(results)
|
52 |
+
else:
|
53 |
+
st.info("Query executed successfully but returned no results.")
|
54 |
+
|
55 |
+
except Exception as e:
|
56 |
+
st.error(f"Error: {str(e)}")
|
57 |
+
st.write("Please try rephrasing your query or check if the requested data exists in the database.")
|
58 |
else:
|
59 |
+
st.warning("Please enter a query to proceed.")
|