Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +20 -23
src/streamlit_app.py
CHANGED
@@ -5,18 +5,15 @@ import streamlit as st
|
|
5 |
import fitz # PyMuPDF
|
6 |
from transformers import pipeline
|
7 |
|
8 |
-
#
|
9 |
-
st.set_page_config(page_title="
|
10 |
|
11 |
-
#
|
12 |
-
st.
|
13 |
-
st.write("Upload your PDF notes below and get a smart AI-generated summary instantly.")
|
14 |
-
|
15 |
-
# Load model only when needed
|
16 |
-
@st.cache_resource(show_spinner=False)
|
17 |
def load_summarizer():
|
18 |
return pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
19 |
|
|
|
20 |
# Extract text from uploaded PDF
|
21 |
def extract_text_from_pdf(uploaded_file):
|
22 |
text = ""
|
@@ -25,7 +22,7 @@ def extract_text_from_pdf(uploaded_file):
|
|
25 |
for page in doc:
|
26 |
text += page.get_text()
|
27 |
except Exception as e:
|
28 |
-
st.error(f"β Error
|
29 |
return text
|
30 |
|
31 |
# Summarize large text
|
@@ -37,38 +34,38 @@ def summarize_text(text, summarizer, max_chunk_length=2000):
|
|
37 |
summary += result[0]['summary_text'] + "\n"
|
38 |
return summary.strip()
|
39 |
|
40 |
-
#
|
|
|
|
|
|
|
41 |
tab1, tab2, tab3 = st.tabs(["π Summarize Notes", "β Ask a Doubt", "π¬ Feedback"])
|
42 |
|
43 |
-
# Tab 1: Summarize
|
44 |
with tab1:
|
|
|
|
|
45 |
uploaded_pdf = st.file_uploader("Upload your PDF notes (PDF only)", type=["pdf"])
|
46 |
|
47 |
if uploaded_pdf:
|
48 |
-
with st.spinner("
|
49 |
pdf_text = extract_text_from_pdf(uploaded_pdf)
|
50 |
|
51 |
if pdf_text.strip():
|
52 |
-
st.
|
53 |
-
st.
|
54 |
-
st.text_area("Extracted Text", pdf_text[:1000] + "...", height=200)
|
55 |
|
56 |
-
if st.button("βοΈ Summarize
|
57 |
-
with st.spinner("
|
58 |
-
summarizer = load_summarizer()
|
59 |
summary = summarize_text(pdf_text, summarizer)
|
60 |
-
st.subheader("
|
61 |
st.text_area("Summary Output", summary, height=300)
|
62 |
st.download_button("β¬οΈ Download Summary", summary, file_name="summary.txt")
|
63 |
else:
|
64 |
st.warning("β οΈ No text found in the uploaded PDF.")
|
65 |
|
66 |
-
# Tab 2: Ask a Doubt
|
67 |
with tab2:
|
68 |
st.header("β Ask a Doubt")
|
69 |
-
st.info("π§ This feature is
|
70 |
|
71 |
-
# Tab 3: Feedback
|
72 |
with tab3:
|
73 |
st.header("π¬ User Feedback")
|
74 |
-
st.info("π¬ A feedback form will be added here to
|
|
|
5 |
import fitz # PyMuPDF
|
6 |
from transformers import pipeline
|
7 |
|
8 |
+
# Set page config
|
9 |
+
st.set_page_config(page_title="PrepPal", page_icon="π", layout="wide")
|
10 |
|
11 |
+
# Load summarizer model
|
12 |
+
@st.cache_resource
|
|
|
|
|
|
|
|
|
13 |
def load_summarizer():
|
14 |
return pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
15 |
|
16 |
+
|
17 |
# Extract text from uploaded PDF
|
18 |
def extract_text_from_pdf(uploaded_file):
|
19 |
text = ""
|
|
|
22 |
for page in doc:
|
23 |
text += page.get_text()
|
24 |
except Exception as e:
|
25 |
+
st.error(f"β Error extracting text from PDF: {e}")
|
26 |
return text
|
27 |
|
28 |
# Summarize large text
|
|
|
34 |
summary += result[0]['summary_text'] + "\n"
|
35 |
return summary.strip()
|
36 |
|
37 |
+
# Load model
|
38 |
+
summarizer = load_summarizer()
|
39 |
+
|
40 |
+
# UI
|
41 |
tab1, tab2, tab3 = st.tabs(["π Summarize Notes", "β Ask a Doubt", "π¬ Feedback"])
|
42 |
|
|
|
43 |
with tab1:
|
44 |
+
st.header("π Upload Notes & Get Summary")
|
45 |
+
st.write("Upload your class notes in PDF format to receive a summarized version.")
|
46 |
uploaded_pdf = st.file_uploader("Upload your PDF notes (PDF only)", type=["pdf"])
|
47 |
|
48 |
if uploaded_pdf:
|
49 |
+
with st.spinner("Extracting text from PDF..."):
|
50 |
pdf_text = extract_text_from_pdf(uploaded_pdf)
|
51 |
|
52 |
if pdf_text.strip():
|
53 |
+
st.subheader("π Extracted Text (Preview)")
|
54 |
+
st.text_area("Raw Text", pdf_text[:1000] + "...", height=200)
|
|
|
55 |
|
56 |
+
if st.button("βοΈ Summarize"):
|
57 |
+
with st.spinner("Summarizing... Please wait."):
|
|
|
58 |
summary = summarize_text(pdf_text, summarizer)
|
59 |
+
st.subheader("β
Summary")
|
60 |
st.text_area("Summary Output", summary, height=300)
|
61 |
st.download_button("β¬οΈ Download Summary", summary, file_name="summary.txt")
|
62 |
else:
|
63 |
st.warning("β οΈ No text found in the uploaded PDF.")
|
64 |
|
|
|
65 |
with tab2:
|
66 |
st.header("β Ask a Doubt")
|
67 |
+
st.info("π§ This feature is under development. Youβll soon be able to chat with your notes using AI!")
|
68 |
|
|
|
69 |
with tab3:
|
70 |
st.header("π¬ User Feedback")
|
71 |
+
st.info("π¬ A feedback form will be added here to collect your thoughts and improve PrepPal.")
|