Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ from PyPDF2 import PdfReader
|
|
3 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
from gtts import gTTS
|
5 |
from io import BytesIO
|
|
|
|
|
6 |
import base64
|
7 |
import re
|
8 |
|
@@ -41,14 +43,13 @@ def summarize_pdf_abstract(pdf_file):
|
|
41 |
|
42 |
# Generate audio
|
43 |
speech = gTTS(text=summary_sentence, lang="en")
|
44 |
-
speech_bytes = BytesIO()
|
45 |
-
speech.write_to_fp(speech_bytes)
|
46 |
|
47 |
-
#
|
48 |
-
|
|
|
49 |
|
50 |
-
# Return
|
51 |
-
return summary_sentence,
|
52 |
|
53 |
except Exception as e:
|
54 |
raise Exception(str(e))
|
@@ -59,4 +60,4 @@ interface = gr.Interface(
|
|
59 |
outputs=[gr.Textbox(label="Summary"), gr.Audio()],
|
60 |
)
|
61 |
|
62 |
-
interface.launch(share=True)
|
|
|
3 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
from gtts import gTTS
|
5 |
from io import BytesIO
|
6 |
+
import pydub
|
7 |
+
from pydub import AudioSegment
|
8 |
import base64
|
9 |
import re
|
10 |
|
|
|
43 |
|
44 |
# Generate audio
|
45 |
speech = gTTS(text=summary_sentence, lang="en")
|
|
|
|
|
46 |
|
47 |
+
# Save audio file
|
48 |
+
audio_file = AudioSegment.from_file(speech, format="mp3")
|
49 |
+
audio_file.export("summary.mp3", format="mp3")
|
50 |
|
51 |
+
# Return summary and audio filename
|
52 |
+
return summary_sentence, "summary.mp3"
|
53 |
|
54 |
except Exception as e:
|
55 |
raise Exception(str(e))
|
|
|
60 |
outputs=[gr.Textbox(label="Summary"), gr.Audio()],
|
61 |
)
|
62 |
|
63 |
+
interface.launch(share=True)
|