Spaces:
Sleeping
Sleeping
File size: 2,501 Bytes
90c325f c8f0869 90c325f 881b2b7 c8f0869 90c325f 881b2b7 52621a3 881b2b7 52621a3 881b2b7 52621a3 |
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 |
import os
os.environ["TRANSFORMERS_CACHE"] = "/app/.cache"
import streamlit as st
import fitz # PyMuPDF
from transformers import pipeline
# Set page config
st.set_page_config(page_title="PrepPal", page_icon="π", layout="wide")
# Load summarizer model
@st.cache_resource
def load_summarizer():
return pipeline("summarization", model="t5-small")
# PDF text extraction
def extract_text_from_pdf(uploaded_file):
text = ""
try:
with fitz.open(stream=uploaded_file.read(), filetype="pdf") as doc:
for page in doc:
text += page.get_text()
except Exception as e:
st.error(f"Error extracting text from PDF: {e}")
return text
# Summarize text in chunks
def summarize_text(text, summarizer, max_chunk_length=2000):
chunks = [text[i:i + max_chunk_length] for i in range(0, len(text), max_chunk_length)]
summary = ""
for chunk in chunks:
result = summarizer(chunk, max_length=130, min_length=30, do_sample=False)
summary += result[0]['summary_text'] + "\n"
return summary.strip()
summarizer = load_summarizer()
tab1, tab2, tab3 = st.tabs(["π Summarize Notes", "β Ask a Doubt", "π¬ Feedback"])
with tab1:
st.header("π Upload Notes & Get Summary")
st.write("Upload your class notes in PDF format to receive a summarized version.")
uploaded_pdf = st.file_uploader("Upload your PDF notes (PDF only)", type=["pdf"])
if uploaded_pdf:
with st.spinner("Extracting text from PDF..."):
pdf_text = extract_text_from_pdf(uploaded_pdf)
if pdf_text.strip():
st.subheader("π Extracted Text (Preview)")
st.text_area("Raw Text", pdf_text[:1000] + "...", height=200)
if st.button("βοΈ Summarize"):
with st.spinner("Summarizing... Please wait."):
summary = summarize_text(pdf_text, summarizer)
st.subheader("β
Summary")
st.text_area("Summary Output", summary, height=300)
st.download_button("β¬οΈ Download Summary", summary, file_name="summary.txt")
else:
st.warning("β οΈ No text found in the uploaded PDF.")
with tab2:
st.header("β Ask a Doubt")
st.info("π§ This feature is under development. Youβll soon be able to chat with your notes using AI!")
with tab3:
st.header("π¬ User Feedback")
st.info("π¬ A feedback form will be added here to collect your thoughts and improve PrepPal.")
|