Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import warnings
|
|
| 9 |
warnings.filterwarnings("ignore")
|
| 10 |
|
| 11 |
class PDFSummarizer:
|
| 12 |
-
def
|
| 13 |
# Use a much faster, lighter model for summarization
|
| 14 |
self.model_name = "sshleifer/distilbart-cnn-12-6" # Much faster than BART-large
|
| 15 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -156,7 +156,7 @@ class PDFSummarizer:
|
|
| 156 |
|
| 157 |
# Create statistics
|
| 158 |
summary_stats = f"""
|
| 159 |
-
π Document Statistics
|
| 160 |
- Original word count: {word_count:,}
|
| 161 |
- Original character count: {char_count:,}
|
| 162 |
- Pages processed: {len(chunks)}
|
|
@@ -189,7 +189,8 @@ def summarize_pdf_interface(pdf_file, summary_type):
|
|
| 189 |
|
| 190 |
except Exception as e:
|
| 191 |
return f"β Error: {str(e)}", "", ""
|
| 192 |
-
|
|
|
|
| 193 |
def create_interface():
|
| 194 |
with gr.Blocks(
|
| 195 |
title="π AI PDF Summarizer",
|
|
@@ -212,8 +213,8 @@ def create_interface():
|
|
| 212 |
Upload any PDF document and get an intelligent summary in seconds!
|
| 213 |
Perfect for research papers, reports, articles, and books.
|
| 214 |
|
| 215 |
-
Features
|
| 216 |
-
-
|
| 217 |
- π Document statistics
|
| 218 |
- π― Multiple summary lengths
|
| 219 |
- π Smart text chunking
|
|
@@ -264,15 +265,15 @@ def create_interface():
|
|
| 264 |
gr.Markdown("""
|
| 265 |
## π‘ Tips for Best Results:
|
| 266 |
|
| 267 |
-
- File Quality
|
| 268 |
-
- Length
|
| 269 |
-
- Language
|
| 270 |
-
- Format
|
| 271 |
|
| 272 |
## π§ Technical Details:
|
| 273 |
-
- Model
|
| 274 |
-
- Processing
|
| 275 |
-
- Speed
|
| 276 |
""")
|
| 277 |
|
| 278 |
# Connect the button to the function
|
|
@@ -292,6 +293,6 @@ def create_interface():
|
|
| 292 |
return interface
|
| 293 |
|
| 294 |
# Launch the application
|
| 295 |
-
if
|
| 296 |
interface = create_interface()
|
| 297 |
interface.launch()
|
|
|
|
| 9 |
warnings.filterwarnings("ignore")
|
| 10 |
|
| 11 |
class PDFSummarizer:
|
| 12 |
+
def __init__(self):
|
| 13 |
# Use a much faster, lighter model for summarization
|
| 14 |
self.model_name = "sshleifer/distilbart-cnn-12-6" # Much faster than BART-large
|
| 15 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 156 |
|
| 157 |
# Create statistics
|
| 158 |
summary_stats = f"""
|
| 159 |
+
π **Document Statistics:**
|
| 160 |
- Original word count: {word_count:,}
|
| 161 |
- Original character count: {char_count:,}
|
| 162 |
- Pages processed: {len(chunks)}
|
|
|
|
| 189 |
|
| 190 |
except Exception as e:
|
| 191 |
return f"β Error: {str(e)}", "", ""
|
| 192 |
+
|
| 193 |
+
# Create Gradio interface
|
| 194 |
def create_interface():
|
| 195 |
with gr.Blocks(
|
| 196 |
title="π AI PDF Summarizer",
|
|
|
|
| 213 |
Upload any PDF document and get an intelligent summary in seconds!
|
| 214 |
Perfect for research papers, reports, articles, and books.
|
| 215 |
|
| 216 |
+
**Features:**
|
| 217 |
+
- β‘ Fast processing with BART model
|
| 218 |
- π Document statistics
|
| 219 |
- π― Multiple summary lengths
|
| 220 |
- π Smart text chunking
|
|
|
|
| 265 |
gr.Markdown("""
|
| 266 |
## π‘ Tips for Best Results:
|
| 267 |
|
| 268 |
+
- **File Quality**: Ensure your PDF has selectable text (not just images)
|
| 269 |
+
- **Length**: Works best with documents between 500-10,000 words
|
| 270 |
+
- **Language**: Optimized for English content
|
| 271 |
+
- **Format**: Clean, well-formatted PDFs produce better summaries
|
| 272 |
|
| 273 |
## π§ Technical Details:
|
| 274 |
+
- **Model**: Facebook BART-Large-CNN (state-of-the-art summarization)
|
| 275 |
+
- **Processing**: Smart text chunking with overlap prevention
|
| 276 |
+
- **Speed**: GPU-accelerated when available
|
| 277 |
""")
|
| 278 |
|
| 279 |
# Connect the button to the function
|
|
|
|
| 293 |
return interface
|
| 294 |
|
| 295 |
# Launch the application
|
| 296 |
+
if __name__ == "__main__":
|
| 297 |
interface = create_interface()
|
| 298 |
interface.launch()
|