Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| # API_CHAT_URL = "http://localhost:8000/chat/" | |
| # API_UPLOAD_URL = "http://localhost:8000/upload/" | |
| API_CHAT_URL = "https://dewasheesh-helpdev.hf.space/chat/" | |
| API_UPLOAD_URL = "https://dewasheesh-helpdev.hf.space/upload/" | |
| st.title("π HelpDevelopers RAG Chatbot") | |
| # PDF Upload Section | |
| st.header("π€ Upload a PDF") | |
| uploaded_file = st.file_uploader("Choose a PDF to upload", type="pdf") | |
| if uploaded_file is not None: | |
| if st.button("Upload"): | |
| with st.spinner("Uploading..."): | |
| files = {"file": (uploaded_file.name, | |
| uploaded_file, "application/pdf")} | |
| res = requests.post(API_UPLOAD_URL, files=files) | |
| if res.status_code == 200: | |
| st.success(f"{uploaded_file.name} uploaded successfully!") | |
| else: | |
| st.error("Upload failed.") | |
| # Chat Section | |
| st.header("π¬ Ask a Question") | |
| query = st.text_input("Your question:") | |
| if st.button("Submit"): | |
| if query: | |
| with st.spinner("Thinking..."): | |
| res = requests.post(API_CHAT_URL, json={ | |
| "query": query, "top_k": 3}) | |
| if res.status_code == 200: | |
| st.success(res.json().get("answer", "No response.")) | |
| else: | |
| st.error(f"Error: {res.text}") | |