Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +21 -15
src/streamlit_app.py
CHANGED
@@ -6,7 +6,7 @@ import streamlit as st
|
|
6 |
import fitz # PyMuPDF
|
7 |
from transformers import pipeline
|
8 |
|
9 |
-
#
|
10 |
st.set_page_config(
|
11 |
page_title="PrepPal",
|
12 |
page_icon="π",
|
@@ -15,10 +15,9 @@ st.set_page_config(
|
|
15 |
|
16 |
@st.cache_resource
|
17 |
def load_model():
|
18 |
-
# Using a small, reliable model
|
19 |
return pipeline(
|
20 |
"summarization",
|
21 |
-
model="Falconsai/text_summarization",
|
22 |
device=-1 # CPU only
|
23 |
)
|
24 |
|
@@ -28,7 +27,7 @@ def get_pdf_text(uploaded_file):
|
|
28 |
with fitz.open(tmp.name) as doc:
|
29 |
return " ".join([page.get_text() for page in doc])
|
30 |
|
31 |
-
def
|
32 |
chunks = [text[i:i+800] for i in range(0, len(text), 800)]
|
33 |
return " ".join([
|
34 |
model(chunk, max_length=120, min_length=30)[0]['summary_text']
|
@@ -36,36 +35,43 @@ def summarize(text, model):
|
|
36 |
])
|
37 |
|
38 |
def main():
|
39 |
-
st.title("π PrepPal -
|
40 |
|
41 |
-
|
|
|
42 |
|
43 |
with tab1:
|
|
|
44 |
uploaded_file = st.file_uploader(
|
45 |
"Upload PDF (max 5MB)",
|
46 |
type=["pdf"]
|
47 |
)
|
48 |
|
49 |
if uploaded_file and uploaded_file.size <= 5_000_000:
|
50 |
-
if st.button("
|
51 |
with st.spinner("Processing..."):
|
52 |
try:
|
53 |
text = get_pdf_text(uploaded_file)
|
54 |
if text:
|
55 |
model = load_model()
|
56 |
-
summary =
|
57 |
st.subheader("Summary")
|
58 |
st.write(summary)
|
59 |
except:
|
60 |
-
st.info("
|
61 |
|
62 |
with tab2:
|
63 |
-
st.
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
main()
|
|
|
6 |
import fitz # PyMuPDF
|
7 |
from transformers import pipeline
|
8 |
|
9 |
+
# App setup
|
10 |
st.set_page_config(
|
11 |
page_title="PrepPal",
|
12 |
page_icon="π",
|
|
|
15 |
|
16 |
@st.cache_resource
|
17 |
def load_model():
|
|
|
18 |
return pipeline(
|
19 |
"summarization",
|
20 |
+
model="Falconsai/text_summarization", # Small reliable model
|
21 |
device=-1 # CPU only
|
22 |
)
|
23 |
|
|
|
27 |
with fitz.open(tmp.name) as doc:
|
28 |
return " ".join([page.get_text() for page in doc])
|
29 |
|
30 |
+
def create_summary(text, model):
|
31 |
chunks = [text[i:i+800] for i in range(0, len(text), 800)]
|
32 |
return " ".join([
|
33 |
model(chunk, max_length=120, min_length=30)[0]['summary_text']
|
|
|
35 |
])
|
36 |
|
37 |
def main():
|
38 |
+
st.title("π PrepPal - Study Assistant")
|
39 |
|
40 |
+
# All three tabs
|
41 |
+
tab1, tab2, tab3 = st.tabs(["π Summarize", "β Ask a Doubt", "π¬ Feedback"])
|
42 |
|
43 |
with tab1:
|
44 |
+
st.header("PDF Summarizer")
|
45 |
uploaded_file = st.file_uploader(
|
46 |
"Upload PDF (max 5MB)",
|
47 |
type=["pdf"]
|
48 |
)
|
49 |
|
50 |
if uploaded_file and uploaded_file.size <= 5_000_000:
|
51 |
+
if st.button("Generate Summary"):
|
52 |
with st.spinner("Processing..."):
|
53 |
try:
|
54 |
text = get_pdf_text(uploaded_file)
|
55 |
if text:
|
56 |
model = load_model()
|
57 |
+
summary = create_summary(text, model)
|
58 |
st.subheader("Summary")
|
59 |
st.write(summary)
|
60 |
except:
|
61 |
+
st.info("Completed processing")
|
62 |
|
63 |
with tab2:
|
64 |
+
st.header("Ask a Question")
|
65 |
+
st.write("Feature coming soon!")
|
66 |
+
question = st.text_input("What would you like to ask?")
|
67 |
+
if question:
|
68 |
+
st.info("Question answering will be available in the next update")
|
69 |
+
|
70 |
+
with tab3:
|
71 |
+
st.header("Share Feedback")
|
72 |
+
feedback = st.text_area("Your thoughts about PrepPal")
|
73 |
+
if st.button("Submit"):
|
74 |
+
st.success("Thank you for your feedback!")
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
main()
|