pdf-chatbot-ui / app.py
sdas2485's picture
Create app.py
669cd0e verified
import streamlit as st
import requests
# Backend API URL
UPLOAD_URL = "http://127.0.0.1:5000/upload"
CHAT_URL = "http://127.0.0.1:5000/chat"
st.title("πŸ“„ AI-Powered PDF Chatbot")
st.sidebar.header("Upload a PDF")
# File Upload
uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type=["pdf"])
if uploaded_file:
files = {"file": uploaded_file.getvalue()}
response = requests.post(UPLOAD_URL, files=files)
if response.status_code == 200:
st.sidebar.success("βœ… PDF Uploaded Successfully!")
else:
st.sidebar.error("❌ Error Uploading PDF")
# Chat Interface
st.subheader("Ask a Question About the PDF")
user_query = st.text_input("Enter your question:")
if st.button("Ask AI"):
if user_query:
payload = {"query": user_query}
response = requests.post(CHAT_URL, json=payload)
if response.status_code == 200:
st.write("πŸ€– AI Response:", response.json()["response"])
else:
st.error("❌ Error in AI Response")
else:
st.warning("⚠️ Please enter a question.")