Spaces:
Build error
Build error
Download app.py from subashpoudel/Document-Interaction-FASTAPI: direct link, hf CLI and curl.
- Browser
- Download file 914 Bytes
-
https://huggingface.co/spaces/subashpoudel/Document-Interaction-FASTAPI/resolve/main/app.py
- Command line
-
hf download hf://spaces/subashpoudel/Document-Interaction-FASTAPI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/subashpoudel/Document-Interaction-FASTAPI/resolve/main/app.py
914 Bytes
| 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.") | |