Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +37 -0
- frontend.py +37 -0
- requirements.txt +3 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
-
|
| 11 |
-
COPY requirements.txt ./
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
RUN pip3 install -r requirements.txt
|
| 12 |
|
| 13 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
|
|
|
| 15 |
|
| 16 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Backend URL (if deployed together on Hugging Face, use relative URL)
|
| 7 |
+
BACKEND_URL = "https://gauravsahu1990-Chabot_Backend.hf.space/api/ask" # Change to your Space/EC2 endpoint if remote
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="ChatSQL Assistant", page_icon="๐ง ", layout="wide")
|
| 10 |
+
|
| 11 |
+
st.title("๐ง ChatSQL Assistant")
|
| 12 |
+
st.write("Ask your question about the database โ Iโll show the result and chart!")
|
| 13 |
+
|
| 14 |
+
# User input
|
| 15 |
+
question = st.text_input("๐ฌ Ask your question:", placeholder="e.g., Show total order amount by customer")
|
| 16 |
+
|
| 17 |
+
if st.button("Ask"):
|
| 18 |
+
if not question.strip():
|
| 19 |
+
st.warning("Please enter a question.")
|
| 20 |
+
else:
|
| 21 |
+
with st.spinner("Thinking..."):
|
| 22 |
+
try:
|
| 23 |
+
response = requests.post(BACKEND_URL, json={"question": question})
|
| 24 |
+
data = response.json()
|
| 25 |
+
|
| 26 |
+
st.markdown("### ๐ Result")
|
| 27 |
+
st.markdown(data.get("answer", ""), unsafe_allow_html=True)
|
| 28 |
+
|
| 29 |
+
if data.get("chart"):
|
| 30 |
+
st.markdown("### ๐ Visualization")
|
| 31 |
+
img_bytes = base64.b64decode(data["chart"])
|
| 32 |
+
st.image(img_bytes, use_container_width=True)
|
| 33 |
+
else:
|
| 34 |
+
st.info("No chart available for this query.")
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
st.error(f"โ ๏ธ Error: {e}")
|
frontend.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
# Backend URL (if deployed together on Hugging Face, use relative URL)
|
| 7 |
+
BACKEND_URL = "https://gauravsahu1990-Chabot_Backend.hf.space/api/ask" # Change to your Space/EC2 endpoint if remote
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="ChatSQL Assistant", page_icon="๐ง ", layout="wide")
|
| 10 |
+
|
| 11 |
+
st.title("๐ง ChatSQL Assistant")
|
| 12 |
+
st.write("Ask your question about the database โ Iโll show the result and chart!")
|
| 13 |
+
|
| 14 |
+
# User input
|
| 15 |
+
question = st.text_input("๐ฌ Ask your question:", placeholder="e.g., Show total order amount by customer")
|
| 16 |
+
|
| 17 |
+
if st.button("Ask"):
|
| 18 |
+
if not question.strip():
|
| 19 |
+
st.warning("Please enter a question.")
|
| 20 |
+
else:
|
| 21 |
+
with st.spinner("Thinking..."):
|
| 22 |
+
try:
|
| 23 |
+
response = requests.post(BACKEND_URL, json={"question": question})
|
| 24 |
+
data = response.json()
|
| 25 |
+
|
| 26 |
+
st.markdown("### ๐ Result")
|
| 27 |
+
st.markdown(data.get("answer", ""), unsafe_allow_html=True)
|
| 28 |
+
|
| 29 |
+
if data.get("chart"):
|
| 30 |
+
st.markdown("### ๐ Visualization")
|
| 31 |
+
img_bytes = base64.b64decode(data["chart"])
|
| 32 |
+
st.image(img_bytes, use_container_width=True)
|
| 33 |
+
else:
|
| 34 |
+
st.info("No chart available for this query.")
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
st.error(f"โ ๏ธ Error: {e}")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|