sdas2485 commited on
Commit
669cd0e
·
verified ·
1 Parent(s): da2a3db

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # Backend API URL
5
+ UPLOAD_URL = "http://127.0.0.1:5000/upload"
6
+ CHAT_URL = "http://127.0.0.1:5000/chat"
7
+
8
+ st.title("📄 AI-Powered PDF Chatbot")
9
+ st.sidebar.header("Upload a PDF")
10
+
11
+ # File Upload
12
+ uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type=["pdf"])
13
+ if uploaded_file:
14
+ files = {"file": uploaded_file.getvalue()}
15
+ response = requests.post(UPLOAD_URL, files=files)
16
+ if response.status_code == 200:
17
+ st.sidebar.success("✅ PDF Uploaded Successfully!")
18
+ else:
19
+ st.sidebar.error("❌ Error Uploading PDF")
20
+
21
+ # Chat Interface
22
+ st.subheader("Ask a Question About the PDF")
23
+ user_query = st.text_input("Enter your question:")
24
+ if st.button("Ask AI"):
25
+ if user_query:
26
+ payload = {"query": user_query}
27
+ response = requests.post(CHAT_URL, json=payload)
28
+ if response.status_code == 200:
29
+ st.write("🤖 AI Response:", response.json()["response"])
30
+ else:
31
+ st.error("❌ Error in AI Response")
32
+ else:
33
+ st.warning("⚠️ Please enter a question.")