Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import pandas as pd | |
| # Backend URL (if deployed together on Hugging Face, use relative URL) | |
| BACKEND_URL = "https://gauravsahu1990-Chabot_Backend.hf.space/api/ask" # Change to your Space/EC2 endpoint if remote | |
| st.set_page_config(page_title="ChatSQL Assistant", page_icon="π§ ", layout="wide") | |
| st.title("π§ ChatSQL Assistant") | |
| st.write("Ask your question about the database β Iβll show the result and chart!") | |
| # User input | |
| question = st.text_input("π¬ Ask your question:", placeholder="e.g., Show total order amount by customer") | |
| if st.button("Ask"): | |
| if not question.strip(): | |
| st.warning("Please enter a question.") | |
| else: | |
| with st.spinner("Thinking..."): | |
| try: | |
| response = requests.post(BACKEND_URL, json={"question": question}) | |
| data = response.json() | |
| st.markdown("### π Result") | |
| st.markdown(data.get("answer", ""), unsafe_allow_html=True) | |
| if data.get("chart"): | |
| st.markdown("### π Visualization") | |
| img_bytes = base64.b64decode(data["chart"]) | |
| st.image(img_bytes, use_container_width=True) | |
| else: | |
| st.info("No chart available for this query.") | |
| except Exception as e: | |
| st.error(f"β οΈ Error: {e}") | |