Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -12
src/streamlit_app.py
CHANGED
@@ -1,16 +1,17 @@
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import fitz # PyMuPDF
|
3 |
from transformers import pipeline
|
4 |
-
import tempfile
|
5 |
|
6 |
# Set page config
|
7 |
st.set_page_config(page_title="PrepPal", page_icon="π", layout="wide")
|
8 |
|
9 |
-
# Load summarizer model
|
10 |
@st.cache_resource
|
11 |
def load_summarizer():
|
12 |
-
|
13 |
-
return pipeline("summarization", model="t5-small", cache_dir=temp_cache_dir)
|
14 |
|
15 |
# Extract text from uploaded PDF
|
16 |
def extract_text_from_pdf(uploaded_file):
|
@@ -23,7 +24,7 @@ def extract_text_from_pdf(uploaded_file):
|
|
23 |
st.error(f"β Error extracting text from PDF: {e}")
|
24 |
return text
|
25 |
|
26 |
-
# Summarize large text
|
27 |
def summarize_text(text, summarizer, max_chunk_length=2000):
|
28 |
chunks = [text[i:i + max_chunk_length] for i in range(0, len(text), max_chunk_length)]
|
29 |
summary = ""
|
@@ -32,20 +33,19 @@ def summarize_text(text, summarizer, max_chunk_length=2000):
|
|
32 |
summary += result[0]['summary_text'] + "\n"
|
33 |
return summary.strip()
|
34 |
|
35 |
-
# Load
|
36 |
summarizer = load_summarizer()
|
37 |
|
38 |
-
#
|
39 |
tab1, tab2, tab3 = st.tabs(["π Summarize Notes", "β Ask a Doubt", "π¬ Feedback"])
|
40 |
|
41 |
-
# Tab 1: Upload and summarize notes
|
42 |
with tab1:
|
43 |
st.header("π Upload Notes & Get Summary")
|
44 |
st.write("Upload your class notes in PDF format to receive a summarized version.")
|
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():
|
@@ -53,7 +53,7 @@ with tab1:
|
|
53 |
st.text_area("Raw Text", pdf_text[:1000] + "...", height=200)
|
54 |
|
55 |
if st.button("βοΈ Summarize"):
|
56 |
-
with st.spinner("
|
57 |
summary = summarize_text(pdf_text, summarizer)
|
58 |
st.subheader("β
Summary")
|
59 |
st.text_area("Summary Output", summary, height=300)
|
@@ -61,12 +61,10 @@ with tab1:
|
|
61 |
else:
|
62 |
st.warning("β οΈ No text found in the uploaded PDF.")
|
63 |
|
64 |
-
# Tab 2: Ask a doubt (placeholder)
|
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 |
-
# Tab 3: Feedback (placeholder)
|
70 |
with tab3:
|
71 |
st.header("π¬ User Feedback")
|
72 |
st.info("π¬ A feedback form will be added here to collect your thoughts and improve PrepPal.")
|
|
|
1 |
+
import os
|
2 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
|
3 |
+
|
4 |
import streamlit as st
|
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="t5-small")
|
|
|
15 |
|
16 |
# Extract text from uploaded PDF
|
17 |
def extract_text_from_pdf(uploaded_file):
|
|
|
24 |
st.error(f"β Error extracting text from PDF: {e}")
|
25 |
return text
|
26 |
|
27 |
+
# Summarize large text
|
28 |
def summarize_text(text, summarizer, max_chunk_length=2000):
|
29 |
chunks = [text[i:i + max_chunk_length] for i in range(0, len(text), max_chunk_length)]
|
30 |
summary = ""
|
|
|
33 |
summary += result[0]['summary_text'] + "\n"
|
34 |
return summary.strip()
|
35 |
|
36 |
+
# Load model
|
37 |
summarizer = load_summarizer()
|
38 |
|
39 |
+
# UI
|
40 |
tab1, tab2, tab3 = st.tabs(["π Summarize Notes", "β Ask a Doubt", "π¬ Feedback"])
|
41 |
|
|
|
42 |
with tab1:
|
43 |
st.header("π Upload Notes & Get Summary")
|
44 |
st.write("Upload your class notes in PDF format to receive a summarized version.")
|
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 PDF..."):
|
49 |
pdf_text = extract_text_from_pdf(uploaded_pdf)
|
50 |
|
51 |
if pdf_text.strip():
|
|
|
53 |
st.text_area("Raw Text", pdf_text[:1000] + "...", height=200)
|
54 |
|
55 |
if st.button("βοΈ Summarize"):
|
56 |
+
with st.spinner("Summarizing... Please wait."):
|
57 |
summary = summarize_text(pdf_text, summarizer)
|
58 |
st.subheader("β
Summary")
|
59 |
st.text_area("Summary Output", summary, height=300)
|
|
|
61 |
else:
|
62 |
st.warning("β οΈ No text found in the uploaded PDF.")
|
63 |
|
|
|
64 |
with tab2:
|
65 |
st.header("β Ask a Doubt")
|
66 |
st.info("π§ This feature is under development. Youβll soon be able to chat with your notes using AI!")
|
67 |
|
|
|
68 |
with tab3:
|
69 |
st.header("π¬ User Feedback")
|
70 |
st.info("π¬ A feedback form will be added here to collect your thoughts and improve PrepPal.")
|