Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
import PyPDF2
|
5 |
+
import pdfplumber
|
6 |
+
|
7 |
+
import torch
|
8 |
+
|
9 |
+
import soundfile as sf
|
10 |
+
|
11 |
+
from IPython.display import Audio
|
12 |
+
|
13 |
+
from datasets import load_dataset
|
14 |
+
|
15 |
+
from pdfminer.high_level import extract_pages, extract_text
|
16 |
+
|
17 |
+
summarization = pipeline ('summarization', model = "pszemraj/long-t5-tglobal-base-16384-book-summary")
|
18 |
+
|
19 |
+
def summarize_and_speech(pdf_file):
|
20 |
+
with open(pdf_file.name, 'rb') as file:
|
21 |
+
pdf_reader = PyPDF2.PdfFileReader(file)
|
22 |
+
abstract_text = pdf_reader.pages[0].extract_text()
|
23 |
+
summary = summarization(abstract_text, max_length=13, min_length=10)[0]['summary_text']
|
24 |
+
|
25 |
+
# Use a text-to-speech model to generate audio
|
26 |
+
synthesiser = pipeline("text-to-speech", "facebook/mms-tts-eng")
|
27 |
+
tts_output = synthesiser(summary)
|
28 |
+
audio_data = tts_output[0]["audio"]
|
29 |
+
|
30 |
+
return summary, audio_data
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn= summarize_and_speech,
|
34 |
+
inputs=gr.File(label="Upload PDF", type="binary"),
|
35 |
+
outputs=[gr.Textbox(label="Abstract Summary:"), gr.Audio(type="filepath", label="Summary_Speech")],
|
36 |
+
live=True,
|
37 |
+
title="Abstract_Research_Paper_Summarizer",
|
38 |
+
description="Upload a Research Paper PDF File. The model will generate a one line summary of the Abstract section and a speech audio."
|
39 |
+
)
|
40 |
+
|
41 |
+
iface.launch()
|
42 |
+
|