Spaces:
Sleeping
Sleeping
File size: 1,075 Bytes
9455394 f431baa 9455394 |
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 |
# https://huggingface.co/spaces/Antoniskaraolis/AI_Audio_Processing
# Here are the imports
import gradio as gr
from PyPDF2 import PdfReader
from transformers import pipeline
from gtts import gTTS
import os
# Here is the code
def extract_abstract_from_pdf(file):
reader = PdfReader(file.name)
first_page = reader.pages[0]
text = first_page.extract_text()
return text
def summarize_text(text, model_name='sshleifer/distilbart-cnn-12-6'):
summarizer = pipeline("summarization", model=model_name)
summary = summarizer(text, max_length=75, min_length=20, do_sample=False)
first_sentence = summary[0]['summary_text'].split('.')[0] + '.'
return first_sentence
def process_pdf(file):
abstract = extract_abstract_from_pdf(file)
summary = summarize_text(abstract)
return summary
iface = gr.Interface(
fn=process_pdf,
inputs=gr.File(label="Upload PDF"),
outputs="text",
title="PDF Abstract Summarizer",
description="This app summarizes the abstract from a PDF. Please upload a PDF with an abstract."
)
iface.launch() |