Chat-Bot-Frontend / frontend.py
gauravsahu1990's picture
Upload folder using huggingface_hub
5a89f5c verified
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}")