Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import PyPDF2
|
| 3 |
import gradio as gr
|
|
@@ -9,11 +13,13 @@ import scipy
|
|
| 9 |
from gtts import gTTS
|
| 10 |
from io import BytesIO
|
| 11 |
|
|
|
|
| 12 |
def extract_text(article):
|
| 13 |
pdfReader = PyPDF2.PdfReader(article)
|
| 14 |
pageObj = pdfReader.pages[0]
|
| 15 |
return pageObj.extract_text()
|
| 16 |
|
|
|
|
| 17 |
def summarize_abstract(text):
|
| 18 |
sentences = text.split(". ")
|
| 19 |
for i, sentence in enumerate(sentences):
|
|
@@ -40,6 +46,7 @@ def summarize_abstract(text):
|
|
| 40 |
|
| 41 |
return summary
|
| 42 |
|
|
|
|
| 43 |
def abstract_to_audio(text):
|
| 44 |
tts = gTTS(text, lang='en')
|
| 45 |
buffer = BytesIO()
|
|
@@ -47,6 +54,7 @@ def abstract_to_audio(text):
|
|
| 47 |
buffer.seek(0)
|
| 48 |
return buffer.read()
|
| 49 |
|
|
|
|
| 50 |
def abstract_audio(article):
|
| 51 |
text = extract_text(article)
|
| 52 |
summary = summarize_abstract(text)
|
|
@@ -57,7 +65,7 @@ inputs = gr.File()
|
|
| 57 |
summary_text = gr.Text()
|
| 58 |
audio_summary = gr.Audio()
|
| 59 |
|
| 60 |
-
|
| 61 |
myApp = gr.Interface( fn= abstract_audio, inputs=gr.File(),
|
| 62 |
outputs=[gr.Text(),gr.Audio()], title="Summary of Abstract to Audio ", description="An App that helps you summarises the abstract of an Article\Journal and gives the audio of the summary", examples=["/content/NIPS-2015-hidden-technical-debt-in-machine-learning-systems-Paper.pdf"]
|
| 63 |
)
|
|
|
|
| 1 |
+
# https://huggingface.co/spaces/azsalihu/AbstractSummary_To_Audio
|
| 2 |
+
|
| 3 |
+
# Here are the imports
|
| 4 |
+
|
| 5 |
import torch
|
| 6 |
import PyPDF2
|
| 7 |
import gradio as gr
|
|
|
|
| 13 |
from gtts import gTTS
|
| 14 |
from io import BytesIO
|
| 15 |
|
| 16 |
+
# Extracting Text function
|
| 17 |
def extract_text(article):
|
| 18 |
pdfReader = PyPDF2.PdfReader(article)
|
| 19 |
pageObj = pdfReader.pages[0]
|
| 20 |
return pageObj.extract_text()
|
| 21 |
|
| 22 |
+
# Summarization Function
|
| 23 |
def summarize_abstract(text):
|
| 24 |
sentences = text.split(". ")
|
| 25 |
for i, sentence in enumerate(sentences):
|
|
|
|
| 46 |
|
| 47 |
return summary
|
| 48 |
|
| 49 |
+
# Abstract to Audio Fuction
|
| 50 |
def abstract_to_audio(text):
|
| 51 |
tts = gTTS(text, lang='en')
|
| 52 |
buffer = BytesIO()
|
|
|
|
| 54 |
buffer.seek(0)
|
| 55 |
return buffer.read()
|
| 56 |
|
| 57 |
+
# Combining Extracting text, Summarization, Abstract to Audio functions
|
| 58 |
def abstract_audio(article):
|
| 59 |
text = extract_text(article)
|
| 60 |
summary = summarize_abstract(text)
|
|
|
|
| 65 |
summary_text = gr.Text()
|
| 66 |
audio_summary = gr.Audio()
|
| 67 |
|
| 68 |
+
# Building Gradio Interface
|
| 69 |
myApp = gr.Interface( fn= abstract_audio, inputs=gr.File(),
|
| 70 |
outputs=[gr.Text(),gr.Audio()], title="Summary of Abstract to Audio ", description="An App that helps you summarises the abstract of an Article\Journal and gives the audio of the summary", examples=["/content/NIPS-2015-hidden-technical-debt-in-machine-learning-systems-Paper.pdf"]
|
| 71 |
)
|