Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +38 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,39 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
st.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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}")
|