Spaces:
Runtime error
Runtime error
Commit
·
0dddfdb
1
Parent(s):
5b9d837
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,26 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
from pdfminer.high_level import extract_text
|
| 3 |
-
from huggingface_hub import hf_hub_download
|
| 4 |
-
from balacoon_tts import TTS
|
| 5 |
import gradio as gr
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
def main():
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
model_name = "balacoon/tts" # Set the desired model name here
|
| 26 |
-
model_path = hf_hub_download(repo_id=model_name, filename="model.pt")
|
| 27 |
-
global tts
|
| 28 |
-
tts = TTS(model_path)
|
| 29 |
-
|
| 30 |
-
audio = gr.outputs.Audio(label="Generated Audio", type="numpy")
|
| 31 |
-
|
| 32 |
-
def generate_audio(file):
|
| 33 |
-
return synthesize_audio(file)
|
| 34 |
-
|
| 35 |
-
iface = gr.Interface(
|
| 36 |
-
fn=generate_audio,
|
| 37 |
-
inputs=file_input,
|
| 38 |
-
outputs=audio,
|
| 39 |
-
title="PDF TO SPEECH CONVERTER",
|
| 40 |
-
layout="vertical",
|
| 41 |
-
debug=True
|
| 42 |
-
)
|
| 43 |
|
|
|
|
| 44 |
iface.launch()
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pdf2speech
|
| 3 |
+
from gtts import gTTS
|
| 4 |
+
from tempfile import NamedTemporaryFile
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
def convert_pdf_to_speech(pdf_file):
|
| 8 |
+
text = pdf2speech.extract_text_from_pdf(pdf_file.name)
|
| 9 |
+
tts = gTTS(text=text, lang='en')
|
| 10 |
+
audio_file = NamedTemporaryFile(suffix=".mp3", delete=False)
|
| 11 |
+
tts.save(audio_file.name)
|
| 12 |
+
audio_file.close()
|
| 13 |
+
return audio_file.name
|
| 14 |
+
|
| 15 |
+
def pdf_to_speech(pdf_file):
|
| 16 |
+
audio_file_path = convert_pdf_to_speech(pdf_file)
|
| 17 |
+
return audio_file_path
|
| 18 |
|
| 19 |
def main():
|
| 20 |
+
pdf_input = gr.inputs.File(label="Upload PDF", type="file")
|
| 21 |
+
audio_output = gr.outputs.Audio(label="Generated Audio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
iface = gr.Interface(fn=pdf_to_speech, inputs=pdf_input, outputs=audio_output, title="PDF to Speech Converter")
|
| 24 |
iface.launch()
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|