Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- 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
|