Spaces:
Sleeping
Sleeping
File size: 1,141 Bytes
84038fa |
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 |
import gradio as gr
from transformers import pipeline
import PyPDF2
# Load the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
def summarize_pdf(pdf_file):
try:
# Extract text from the uploaded PDF
pdf_reader = PyPDF2.PdfReader(pdf_file)
text = ""
for page in pdf_reader.pages:
text += page.extract_text()
# Check if text was extracted
if not text.strip():
return "❌ Could not extract text from the PDF. Please upload a valid document."
# Summarize the extracted text
summary = summarizer(text, max_length=300, min_length=50, do_sample=False)
return summary[0]['summary_text']
except Exception as e:
return f"❌ An error occurred: {str(e)}"
# Create the Gradio interface
interface = gr.Interface(
fn=summarize_pdf,
inputs=gr.inputs.File(label="Upload PDF"),
outputs=gr.outputs.Textbox(label="Summary"),
title="PDF Summarizer",
description="Upload a PDF file to extract and summarize its content using state-of-the-art AI."
)
interface.launch()
|