Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -21
src/streamlit_app.py
CHANGED
@@ -5,14 +5,17 @@ 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 |
-
|
13 |
-
|
14 |
-
return pipeline("summarization", model="Falconsai/text_summarization")
|
15 |
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Extract text from uploaded PDF
|
18 |
def extract_text_from_pdf(uploaded_file):
|
@@ -22,7 +25,7 @@ def extract_text_from_pdf(uploaded_file):
|
|
22 |
for page in doc:
|
23 |
text += page.get_text()
|
24 |
except Exception as e:
|
25 |
-
st.error(f"β Error
|
26 |
return text
|
27 |
|
28 |
# Summarize large text
|
@@ -34,38 +37,38 @@ def summarize_text(text, summarizer, max_chunk_length=2000):
|
|
34 |
summary += result[0]['summary_text'] + "\n"
|
35 |
return summary.strip()
|
36 |
|
37 |
-
#
|
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.
|
54 |
-
st.
|
|
|
55 |
|
56 |
-
if st.button("βοΈ Summarize"):
|
57 |
-
with st.spinner("Summarizing...
|
|
|
58 |
summary = summarize_text(pdf_text, summarizer)
|
59 |
-
st.subheader("
|
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
|
68 |
|
|
|
69 |
with tab3:
|
70 |
st.header("π¬ User Feedback")
|
71 |
-
st.info("π¬ A feedback form will be added here to
|
|
|
5 |
import fitz # PyMuPDF
|
6 |
from transformers import pipeline
|
7 |
|
8 |
+
# Page configuration
|
9 |
+
st.set_page_config(page_title="StudyGenie π", layout="centered")
|
10 |
|
11 |
+
# Title
|
12 |
+
st.title("π StudyGenie - Summarize Your Notes")
|
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):
|
|
|
25 |
for page in doc:
|
26 |
text += page.get_text()
|
27 |
except Exception as e:
|
28 |
+
st.error(f"β Error reading PDF: {e}")
|
29 |
return text
|
30 |
|
31 |
# Summarize large text
|
|
|
37 |
summary += result[0]['summary_text'] + "\n"
|
38 |
return summary.strip()
|
39 |
|
40 |
+
# Tabs for multiple functions
|
|
|
|
|
|
|
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("π Extracting text from your PDF..."):
|
49 |
pdf_text = extract_text_from_pdf(uploaded_pdf)
|
50 |
|
51 |
if pdf_text.strip():
|
52 |
+
st.success("β
Text extracted successfully!")
|
53 |
+
st.subheader("πΉ Preview of Extracted Text")
|
54 |
+
st.text_area("Extracted Text", pdf_text[:1000] + "...", height=200)
|
55 |
|
56 |
+
if st.button("βοΈ Summarize Notes"):
|
57 |
+
with st.spinner("π§ Summarizing..."):
|
58 |
+
summarizer = load_summarizer()
|
59 |
summary = summarize_text(pdf_text, summarizer)
|
60 |
+
st.subheader("π Summary")
|
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 coming soon! Youβll be able to chat with your notes using AI.")
|
70 |
|
71 |
+
# Tab 3: Feedback
|
72 |
with tab3:
|
73 |
st.header("π¬ User Feedback")
|
74 |
+
st.info("π¬ A feedback form will be added here to help us improve StudyGenie.")
|