Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,10 @@ from transformers import pipeline
|
|
| 2 |
import fitz # PyMuPDF
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
|
|
|
| 7 |
def extract_text_from_pdf(pdf_file):
|
| 8 |
try:
|
| 9 |
doc = fitz.open(pdf_file.name)
|
|
@@ -14,6 +16,7 @@ def extract_text_from_pdf(pdf_file):
|
|
| 14 |
except Exception as e:
|
| 15 |
return f"Error extracting text from PDF: {e}"
|
| 16 |
|
|
|
|
| 17 |
def summarize_input(text, pdf_file):
|
| 18 |
if pdf_file is not None:
|
| 19 |
text = extract_text_from_pdf(pdf_file)
|
|
@@ -32,6 +35,7 @@ def summarize_input(text, pdf_file):
|
|
| 32 |
except Exception as e:
|
| 33 |
return f"Summarization failed: {e}"
|
| 34 |
|
|
|
|
| 35 |
app = gr.Interface(
|
| 36 |
fn=summarize_input,
|
| 37 |
inputs=[
|
|
|
|
| 2 |
import fitz # PyMuPDF
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load summarization model
|
| 6 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 7 |
|
| 8 |
+
# Extract text from PDF
|
| 9 |
def extract_text_from_pdf(pdf_file):
|
| 10 |
try:
|
| 11 |
doc = fitz.open(pdf_file.name)
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
return f"Error extracting text from PDF: {e}"
|
| 18 |
|
| 19 |
+
# Main summarizer function
|
| 20 |
def summarize_input(text, pdf_file):
|
| 21 |
if pdf_file is not None:
|
| 22 |
text = extract_text_from_pdf(pdf_file)
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Summarization failed: {e}"
|
| 37 |
|
| 38 |
+
# Gradio interface
|
| 39 |
app = gr.Interface(
|
| 40 |
fn=summarize_input,
|
| 41 |
inputs=[
|