AliInamdar commited on
Commit
585517e
Β·
verified Β·
1 Parent(s): ac0fd63

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +13 -4
streamlit_app.py CHANGED
@@ -17,6 +17,18 @@ if not TOGETHER_API_KEY:
17
  # πŸ“‚ File upload
18
  uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # πŸ’¬ User input
21
  user_query = st.text_input("πŸ’¬ Ask a question about your dataset")
22
 
@@ -24,10 +36,6 @@ user_query = st.text_input("πŸ’¬ Ask a question about your dataset")
24
  if st.button("Generate & Run SQL"):
25
  if uploaded_file is not None and user_query.strip():
26
  try:
27
- df = pd.read_excel(uploaded_file)
28
- st.success("βœ… File loaded successfully")
29
- st.dataframe(df.head(3))
30
-
31
  # 🧠 Prompt construction
32
  preview = df.head(5).to_string(index=False)
33
  prompt = f"""
@@ -43,6 +51,7 @@ IMPORTANT:
43
  - Only return a valid SQL query (no Python, no comments, no markdown, no explanations).
44
  - Use SQL compatible with SQLite.
45
  - Table name is 'df'.
 
46
  """
47
 
48
  # πŸ”— Together API request
 
17
  # πŸ“‚ File upload
18
  uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
19
 
20
+ if uploaded_file is not None:
21
+ try:
22
+ df = pd.read_excel(uploaded_file)
23
+ st.success("βœ… File loaded successfully")
24
+ st.subheader("πŸ“„ Preview of Uploaded Data")
25
+ st.dataframe(df.head(10))
26
+ except Exception as e:
27
+ st.error(f"❌ Error reading Excel file: {e}")
28
+ st.stop()
29
+ else:
30
+ st.info("πŸ“‚ Please upload an Excel file to begin.")
31
+
32
  # πŸ’¬ User input
33
  user_query = st.text_input("πŸ’¬ Ask a question about your dataset")
34
 
 
36
  if st.button("Generate & Run SQL"):
37
  if uploaded_file is not None and user_query.strip():
38
  try:
 
 
 
 
39
  # 🧠 Prompt construction
40
  preview = df.head(5).to_string(index=False)
41
  prompt = f"""
 
51
  - Only return a valid SQL query (no Python, no comments, no markdown, no explanations).
52
  - Use SQL compatible with SQLite.
53
  - Table name is 'df'.
54
+ - If column names contain spaces or special characters, wrap them in double quotes.
55
  """
56
 
57
  # πŸ”— Together API request