Spaces:
Sleeping
Sleeping
File size: 1,390 Bytes
5a89f5c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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}")
|