-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (23 loc) · 993 Bytes
/
main.py
File metadata and controls
31 lines (23 loc) · 993 Bytes
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
import streamlit as st
import PyPDF2 # ✅ ab PyPDF2 use karenge
st.set_page_config(page_title="Chat with your PDF", page_icon="📄")
st.title("📄 Chat with your PDF (Simple Version)")
uploaded_file = st.file_uploader("Upload your PDF", type=["pdf"])
if uploaded_file is not None:
reader = PyPDF2.PdfReader(uploaded_file)
text = ""
for page in reader.pages:
if page.extract_text():
text += page.extract_text()
st.success("✅ PDF Uploaded & Text Extracted")
with st.expander("Preview Extracted Text"):
st.write(text[:2000])
query = st.text_input("Ask something about the PDF:")
if query:
if query.lower() in text.lower():
start = text.lower().find(query.lower())
end = start + 300
answer = text[start:end]
st.info(f"🔍 Found something related:\n\n{answer}")
else:
st.warning("❌ No exact match found in the PDF.")