File size: 914 Bytes
fd1c9c4 |
1 2 3 4 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 |
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.")
|