acadiaway commited on
Commit
dab1d38
Β·
1 Parent(s): eda83bc

use API access instaed of downloding the model

Browse files
Files changed (1) hide show
  1. app.py +51 -18
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
- nl_query = st.text_input("Enter your query:", value="List 11 names of ships type schooner")
 
 
 
 
 
 
 
 
7
 
8
- if st.button("Generate & Execute"):
9
- if nl_query:
 
 
 
 
 
 
 
 
 
10
  with st.spinner("Generating SQL and executing query..."):
11
- sql, results = text_to_sql(nl_query)
12
-
13
- st.write("**Generated SQL:**")
14
- st.code(sql, language="sql")
15
-
16
- st.write("**Results:**")
17
- if isinstance(results, list) and results:
18
- st.write(f"Found {len(results)} rows:")
19
- for i, row in enumerate(results[:20]): # Show first 20
20
- st.write(f"Row {i+1}: {row}")
21
- if len(results) > 20:
22
- st.info(f"Showing first 20 rows out of {len(results)} total results.")
23
- else:
24
- st.write(results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  else:
26
- st.error("Enter a query.")
 
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.")