Spaces:
Sleeping
Sleeping
# 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() |