Sourabh572716's picture
Upload folder using huggingface_hub
4cce120 verified
import os, requests, streamlit as st
st.set_page_config(page_title="FoodHub Chatbot", layout="centered")
st.title("FoodHub Customer Support Chatbot")
BACKEND_URL = os.getenv("BACKEND_URL", "https://YOUR-ORG-FoodHubChatBackend.hf.space")
if "messages" not in st.session_state:
st.session_state.messages = []
for m in st.session_state.messages:
with st.chat_message(m["role"]):
st.markdown(m["content"])
prompt = st.chat_input("Ask about your order (e.g., 'Where is my order O12501 for C1026?')")
if prompt:
st.session_state.messages.append({"role":"user","content":prompt})
with st.chat_message("user"):
st.markdown(prompt)
import re
oid = (re.search(r"O\d{5,}", prompt).group(0) if re.search(r"O\d{5,}", prompt) else None)
cid = (re.search(r"C\d{4,}", prompt).group(0) if re.search(r"C\d{4,}", prompt) else None)
try:
r = requests.post(f"{BACKEND_URL}/v1/chat", json={"message": prompt, "order_id": oid, "cust_id": cid}, timeout=30)
reply = r.json().get("reply", "Sorry, something went wrong.")
except Exception as e:
reply = f"Backend error: {e}"
st.session_state.messages.append({"role":"assistant","content":reply})
with st.chat_message("assistant"):
st.markdown(reply)