Alberto Primerano
Final Version
0e6d852
raw
history blame
1.88 kB
"""
This class implments a Gradio interface to generate an audio summary
from the abstract of a PDF article.
"""
import gradio as gr
from gradio_pdf import PDF
from pdf_processor import summarize_abstract
from audio_processor import generate_audio
# Given a PDF file path, this function returns an audio summary of the abstract
def abstract_to_audio(pdf_path):
""" This function retuns the audio generated from the summary of the abstract of PDF file.
Args: (pdf_path : str)
"""
summarized_abstract = summarize_abstract(pdf_path)
audio, sampling_rate = generate_audio(summarized_abstract)
return sampling_rate, audio.T
with gr.Blocks() as abstract_audio:
gr.Markdown("""
# PDF abstract audio summarize
Create an audio summary of the Abstract of the uploaded article.""")
with gr.Row():
pdf_input = PDF(label="PDF File ...", interactive=True)
audio_output = gr.Audio(label="Audio Summary ...")
audio_abstract_button = gr.Button("Generate audio summary")
audio_abstract_button.click(abstract_to_audio, inputs=pdf_input, outputs=audio_output)
gr.Examples(
examples=["Article 11 Hidden Technical Debt in Machine Learning Systems.pdf"],
inputs=pdf_input,
outputs=audio_output,
fn=abstract_to_audio,
cache_examples=False,
)
with gr.Accordion("Information: "):
gr.Markdown("This application creates an audio summary of the Abstract of the uploaded article. \n"
"Make sure that the uploaded article is in the expected format......\n"
"Please note that the summarization is implemented using facebook/bart-large-cnn with maxlength= 50 to provide a meaningful summary and not \n"
"only the first sentence.")
abstract_audio.launch()