Sourabh572716 commited on
Commit
4cce120
·
verified ·
1 Parent(s): 5795e49

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os, requests, streamlit as st
3
+
4
+ st.set_page_config(page_title="FoodHub Chatbot", layout="centered")
5
+ st.title("FoodHub Customer Support Chatbot")
6
+
7
+ BACKEND_URL = os.getenv("BACKEND_URL", "https://YOUR-ORG-FoodHubChatBackend.hf.space")
8
+
9
+ if "messages" not in st.session_state:
10
+ st.session_state.messages = []
11
+
12
+ for m in st.session_state.messages:
13
+ with st.chat_message(m["role"]):
14
+ st.markdown(m["content"])
15
+
16
+ prompt = st.chat_input("Ask about your order (e.g., 'Where is my order O12501 for C1026?')")
17
+ if prompt:
18
+ st.session_state.messages.append({"role":"user","content":prompt})
19
+ with st.chat_message("user"):
20
+ st.markdown(prompt)
21
+
22
+ import re
23
+ oid = (re.search(r"O\d{5,}", prompt).group(0) if re.search(r"O\d{5,}", prompt) else None)
24
+ cid = (re.search(r"C\d{4,}", prompt).group(0) if re.search(r"C\d{4,}", prompt) else None)
25
+
26
+ try:
27
+ r = requests.post(f"{BACKEND_URL}/v1/chat", json={"message": prompt, "order_id": oid, "cust_id": cid}, timeout=30)
28
+ reply = r.json().get("reply", "Sorry, something went wrong.")
29
+ except Exception as e:
30
+ reply = f"Backend error: {e}"
31
+
32
+ st.session_state.messages.append({"role":"assistant","content":reply})
33
+ with st.chat_message("assistant"):
34
+ st.markdown(reply)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit==1.35.0
2
+ requests==2.32.3