Spaces:
Sleeping
Sleeping
Download streamlit_app.py from Haroonk/pdf-summarizer: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/spaces/Haroonk/pdf-summarizer/resolve/main/streamlit_app.py
- Command line
-
hf download hf://spaces/Haroonk/pdf-summarizer/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Haroonk/pdf-summarizer/resolve/main/streamlit_app.py
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*") |