Spaces:
Runtime error
Runtime error
Commit
·
7917b4e
1
Parent(s):
33051d3
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,47 +21,39 @@ def synthesize_audio(file, model_name_str, speaker_str):
|
|
| 21 |
|
| 22 |
def main():
|
| 23 |
logging.basicConfig(level=logging.INFO)
|
| 24 |
-
|
| 25 |
-
gr.Markdown(
|
| 26 |
-
"""
|
| 27 |
-
<h1 align="center">PDF TO SPEECH CONVERTER</h1>
|
| 28 |
-
1. Insert a PDF
|
| 29 |
-
2. Select the model to synthesize with
|
| 30 |
-
3. Select speaker
|
| 31 |
-
4. Hit "Generate" and listen to the result!
|
| 32 |
-
When you select a model for the first time, it may take some time to download it.
|
| 33 |
-
This project is designed to bring the joy of reading without the hassle of looking over.
|
| 34 |
-
If you want an audiobook, you've got it!
|
| 35 |
-
"""
|
| 36 |
-
)
|
| 37 |
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
model_path = hf_hub_download(repo_id="balacoon/tts", filename=model_name_str)
|
| 45 |
-
global tts
|
| 46 |
-
tts = TTS(model_path)
|
| 47 |
-
speakers = tts.get_speakers()
|
| 48 |
-
default_speaker = speakers[-1]
|
| 49 |
-
return speakers, default_speaker
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
return synthesize_audio(file, model_name_str, speaker_str)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
iface.add_input(model_name_dropdown)
|
| 62 |
-
iface.add_input(speaker_dropdown)
|
| 63 |
-
iface.add_output(audio)
|
| 64 |
-
iface.run()
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
main()
|
|
|
|
| 21 |
|
| 22 |
def main():
|
| 23 |
logging.basicConfig(level=logging.INFO)
|
| 24 |
+
file_input = gr.inputs.File(label="Upload PDF")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
model_files = list_repo_files(repo_id="balacoon/tts")
|
| 27 |
+
model_name_dropdown = gr.inputs.Dropdown(label="Model", choices=model_files)
|
| 28 |
|
| 29 |
+
def set_model(model_name_str: str):
|
| 30 |
+
model_path = hf_hub_download(repo_id="balacoon/tts", filename=model_name_str)
|
| 31 |
+
global tts
|
| 32 |
+
tts = TTS(model_path)
|
| 33 |
+
speakers = tts.get_speakers()
|
| 34 |
+
default_speaker = speakers[-1]
|
| 35 |
+
speaker_dropdown.choices = speakers
|
| 36 |
+
return speakers, default_speaker
|
| 37 |
|
| 38 |
+
speaker_dropdown = gr.inputs.Dropdown(label="Speaker", choices=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
audio = gr.outputs.Audio(label="Generated Audio", type="numpy")
|
| 41 |
|
| 42 |
+
def generate_audio(file, model_name_str, speaker_str):
|
| 43 |
+
return synthesize_audio(file, model_name_str, speaker_str)
|
| 44 |
|
| 45 |
+
iface = gr.Interface(
|
| 46 |
+
fn=generate_audio,
|
| 47 |
+
inputs=[file_input, model_name_dropdown, speaker_dropdown],
|
| 48 |
+
outputs=audio,
|
| 49 |
+
title="PDF TO SPEECH CONVERTER",
|
| 50 |
+
layout="rows",
|
| 51 |
+
debug=True
|
| 52 |
+
)
|
| 53 |
|
| 54 |
+
model_name_dropdown.set_action(set_model)
|
|
|
|
| 55 |
|
| 56 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|