Spaces:
Build error
Build error
| import streamlit as st | |
| import requests | |
| # API URL | |
| API_URL = "http://127.0.0.1:8000" | |
| st.title("📄 AI Chatbot for PDF") | |
| # Upload PDF | |
| uploaded_file = st.file_uploader("Upload your PDF", type=["pdf"]) | |
| if uploaded_file: | |
| files = {"file": uploaded_file.getvalue()} | |
| response = requests.post(f"{API_URL}/upload-pdf/", files=files) | |
| if response.status_code == 200: | |
| st.success("PDF processed successfully!") | |
| else: | |
| st.error("Failed to process PDF.") | |
| # Chat UI | |
| query = st.text_input("Ask a question from the PDF") | |
| if st.button("Ask"): | |
| if query: | |
| payload = {"question": query} | |
| response = requests.post(f"{API_URL}/chat/", json=payload) | |
| if response.status_code == 200: | |
| answer = response.json()["response"] | |
| st.markdown(f"**Answer:**\n\n{answer}") | |
| else: | |
| st.error("Error retrieving answer.") | |