Spaces:
Running
Running
File size: 2,330 Bytes
0a190ad 6cb7262 0a190ad c8f0869 90c325f 881b2b7 c8f0869 4c1df41 39720cf f4b5840 39720cf 881b2b7 1163dbb f4b5840 1163dbb bdae30c 1163dbb 93313cc 1163dbb 881b2b7 4c1df41 1163dbb 881b2b7 6cb7262 4c1df41 6cb7262 4c1df41 6cb7262 4c1df41 6cb7262 1163dbb 6cb7262 1163dbb 4c1df41 bdae30c 6cb7262 4c1df41 bdae30c 4c1df41 881b2b7 6cb7262 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import os
import tempfile
os.environ["TRANSFORMERS_CACHE"] = "/cache"
import streamlit as st
import fitz # PyMuPDF
from transformers import pipeline
# App setup
st.set_page_config(
page_title="PrepPal",
page_icon="π",
layout="wide"
)
@st.cache_resource
def load_model():
return pipeline(
"summarization",
model="Falconsai/text_summarization",
device=-1 # CPU only
)
def get_pdf_text(uploaded_file):
with tempfile.NamedTemporaryFile(suffix=".pdf") as tmp:
tmp.write(uploaded_file.getbuffer())
with fitz.open(tmp.name) as doc:
return " ".join([page.get_text() for page in doc])
def create_summary(text, model):
chunks = [text[i:i+800] for i in range(0, len(text), 800)]
return " ".join([
model(chunk, max_length=120, min_length=30)[0]['summary_text']
for chunk in chunks
])
def main():
st.title("π PrepPal - Study Assistant")
# All three tabs
tab1, tab2, tab3 = st.tabs(["π Summarize", "β Ask a Doubt", "π¬ Feedback"])
with tab1:
st.header("PDF Summarizer")
uploaded_file = st.file_uploader(
"Upload PDF (max 5MB)",
type=["pdf"]
)
if uploaded_file and uploaded_file.size <= 5_000_000:
if st.button("Generate Summary"):
with st.spinner("Extracting text..."):
text = get_pdf_text(uploaded_file)
if text: # Only proceed if text extraction succeeded
with st.spinner("Loading AI model..."):
model = load_model()
with st.spinner("Generating summary..."):
summary = create_summary(text, model)
st.subheader("Summary")
st.write(summary)
else:
st.info("Could not extract text from PDF")
with tab2:
st.header("Ask a Question")
st.write("Feature coming soon!")
with tab3:
st.header("Share Feedback")
feedback = st.text_area("Your thoughts about PrepPal")
if st.button("Submit Feedback"):
st.success("Thank you for your feedback!")
if __name__ == "__main__":
main() |