Spaces:
Runtime error
Runtime error
Commit
·
6568e62
1
Parent(s):
535e903
last code had ui , but not working as expected
Browse files
app.py
CHANGED
|
@@ -1,54 +1,43 @@
|
|
| 1 |
import logging
|
| 2 |
-
from typing import cast
|
| 3 |
from pdfminer.high_level import extract_text
|
| 4 |
-
from huggingface_hub import hf_hub_download
|
| 5 |
-
import gradio as gr
|
| 6 |
from balacoon_tts import TTS
|
|
|
|
| 7 |
|
| 8 |
# Global TTS module, initialized from a selected model
|
| 9 |
tts = None
|
| 10 |
-
speakers = []
|
| 11 |
-
default_speaker = None
|
| 12 |
|
| 13 |
def read_pdf(file):
|
| 14 |
text = extract_text(file.name)
|
| 15 |
return text
|
| 16 |
|
| 17 |
-
def synthesize_audio(file
|
| 18 |
text_str = read_pdf(file)
|
| 19 |
if len(text_str) > 1024:
|
| 20 |
text_str = text_str[:1024]
|
| 21 |
-
samples = tts.synthesize(text_str
|
| 22 |
return (samples, tts.get_sampling_rate())
|
| 23 |
|
| 24 |
def main():
|
| 25 |
logging.basicConfig(level=logging.INFO)
|
| 26 |
file_input = gr.inputs.File(label="Upload PDF")
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
model_path = hf_hub_download(repo_id="balacoon/tts", filename=model_name_str)
|
| 33 |
-
global tts, speakers, default_speaker
|
| 34 |
-
tts = TTS(model_path)
|
| 35 |
-
speakers = tts.get_speakers()
|
| 36 |
-
default_speaker = speakers[-1]
|
| 37 |
-
|
| 38 |
-
speaker_dropdown = gr.inputs.Dropdown(label="Speaker", choices=speakers)
|
| 39 |
|
| 40 |
audio = gr.outputs.Audio(label="Generated Audio", type="numpy")
|
| 41 |
|
| 42 |
-
def generate_audio(file
|
| 43 |
-
|
| 44 |
-
return synthesize_audio(file, speaker_str)
|
| 45 |
|
| 46 |
iface = gr.Interface(
|
| 47 |
fn=generate_audio,
|
| 48 |
-
inputs=
|
| 49 |
outputs=audio,
|
| 50 |
title="PDF TO SPEECH CONVERTER",
|
| 51 |
-
layout="
|
| 52 |
debug=True
|
| 53 |
)
|
| 54 |
|
|
|
|
| 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 |
# Global TTS module, initialized from a selected model
|
| 8 |
tts = None
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def read_pdf(file):
|
| 11 |
text = extract_text(file.name)
|
| 12 |
return text
|
| 13 |
|
| 14 |
+
def synthesize_audio(file):
|
| 15 |
text_str = read_pdf(file)
|
| 16 |
if len(text_str) > 1024:
|
| 17 |
text_str = text_str[:1024]
|
| 18 |
+
samples = tts.synthesize(text_str)
|
| 19 |
return (samples, tts.get_sampling_rate())
|
| 20 |
|
| 21 |
def main():
|
| 22 |
logging.basicConfig(level=logging.INFO)
|
| 23 |
file_input = gr.inputs.File(label="Upload PDF")
|
| 24 |
|
| 25 |
+
model_name = "balacoon/tts" # Set the desired model name here
|
| 26 |
+
model_path = hf_hub_download(repo_id=model_name)
|
| 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 |
|