pdf-summarizer / streamlit_app.py
Haroonk's picture
Update streamlit_app.py
ddb617e verified
Raw History Blame Contribute Delete
2.36 kB
import streamlit as st
from utils import extract_text_from_pdf, summarize_with_hf
st.set_page_config(page_title="🧠 Free PDF Summarizer (Cloud)", layout="wide")
st.title("🧠 Free PDF Summarizer (Cloud-Ready)")
st.subheader("Upload any PDF β†’ Get instant summary β€” works on Streamlit Cloud!")
# File uploader
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
if uploaded_file is not None:
try:
# Extract text from PDF
with st.spinner("πŸ“„ Reading PDF..."):
text = extract_text_from_pdf(uploaded_file)
st.success(f"βœ… Successfully read {len(text)} characters from PDF")
# Summary length options
summary_length = st.selectbox(
"Choose summary length:",
["Short (50-100 words)", "Medium (100-200 words)", "Long (200-300 words)"]
)
length_map = {
"Short (50-100 words)": (50, 100),
"Medium (100-200 words)": (100, 200),
"Long (200-300 words)": (200, 300)
}
min_len, max_len = length_map[summary_length]
# Generate summary button
if st.button("✨ Generate Summary", type="primary"):
with st.spinner("🧠 AI is summarizing... (takes 10-30 seconds)"):
summary = summarize_with_hf(text, max_length=max_len, min_length=min_len)
# Display results
col1, col2 = st.columns(2)
with col1:
st.subheader("πŸ“„ Original Text (First 500 chars)")
st.text_area("Original", text[:500] + "...", height=300)
with col2:
st.subheader("✨ AI Summary")
st.text_area("Summary", summary, height=300)
# Download button
st.download_button(
label="πŸ“₯ Download Summary",
data=summary,
file_name="summary.txt",
mime="text/plain"
)
except Exception as e:
st.error(f"❌ Error: {str(e)}")
st.info("Make sure your PDF isn't password-protected or corrupted.")
else:
st.info("πŸ‘† Upload a PDF file to get started")
# Footer
st.markdown("---")
st.markdown("*Powered by Hugging Face transformers β€” 100% free, runs in the cloud*")