Dewasheesh commited on
Commit
d2e5e1c
·
verified ·
1 Parent(s): 12285ab

Upload test.py

Browse files
Files changed (1) hide show
  1. test.py +39 -0
test.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # API_CHAT_URL = "http://localhost:8000/chat/"
5
+ # API_UPLOAD_URL = "http://localhost:8000/upload/"
6
+
7
+ API_CHAT_URL = "https://dewasheesh-helpdev.hf.space/chat/"
8
+ API_UPLOAD_URL = "https://dewasheesh-helpdev.hf.space/upload/"
9
+
10
+
11
+ st.title("📚 HelpDevelopers RAG Chatbot")
12
+
13
+ # PDF Upload Section
14
+ st.header("📤 Upload a PDF")
15
+ uploaded_file = st.file_uploader("Choose a PDF to upload", type="pdf")
16
+
17
+ if uploaded_file is not None:
18
+ if st.button("Upload"):
19
+ with st.spinner("Uploading..."):
20
+ files = {"file": (uploaded_file.name,
21
+ uploaded_file, "application/pdf")}
22
+ res = requests.post(API_UPLOAD_URL, files=files)
23
+ if res.status_code == 200:
24
+ st.success(f"{uploaded_file.name} uploaded successfully!")
25
+ else:
26
+ st.error("Upload failed.")
27
+
28
+ # Chat Section
29
+ st.header("💬 Ask a Question")
30
+ query = st.text_input("Your question:")
31
+ if st.button("Submit"):
32
+ if query:
33
+ with st.spinner("Thinking..."):
34
+ res = requests.post(API_CHAT_URL, json={
35
+ "query": query, "top_k": 3})
36
+ if res.status_code == 200:
37
+ st.success(res.json().get("answer", "No response."))
38
+ else:
39
+ st.error(f"Error: {res.text}")