Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import torch
|
| 4 |
import numpy as np
|
| 5 |
-
device = 0 if torch.cuda.is_available() else -1
|
| 6 |
|
| 7 |
-
|
| 8 |
-
tts_pipe = pipeline("text-to-audio", model="facebook/mms-tts-ukr", device=device)
|
| 9 |
-
except Exception as e:
|
| 10 |
-
tts_pipe = pipeline("text-to-speech", model="facebook/mms-tts-ukr", device=device)
|
| 11 |
|
| 12 |
def generate_audio(text):
|
| 13 |
if not text.strip():
|
|
@@ -15,25 +10,22 @@ def generate_audio(text):
|
|
| 15 |
|
| 16 |
try:
|
| 17 |
result = tts_pipe(text)
|
| 18 |
-
|
| 19 |
sampling_rate = result["sampling_rate"]
|
| 20 |
audio_data = result["audio"]
|
| 21 |
return (sampling_rate, audio_data.astype(np.float32)), "Голос згенеровано успішно!"
|
| 22 |
-
|
| 23 |
except Exception as e:
|
| 24 |
-
return None, f"Помилка
|
| 25 |
|
| 26 |
with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
| 27 |
-
gr.Markdown("#Озвучка задач")
|
| 28 |
-
|
| 29 |
with gr.Row():
|
| 30 |
with gr.Column():
|
| 31 |
-
text_input = gr.Textbox(label="Текст
|
| 32 |
-
btn = gr.Button("
|
| 33 |
with gr.Column():
|
| 34 |
-
audio_out = gr.Audio(label="
|
| 35 |
status = gr.Label(label="Статус")
|
| 36 |
|
| 37 |
btn.click(generate_audio, inputs=text_input, outputs=[audio_out, status])
|
| 38 |
|
| 39 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
|
| 5 |
+
tts_pipe = pipeline("text-to-speech", model="facebook/mms-tts-ukr")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def generate_audio(text):
|
| 8 |
if not text.strip():
|
|
|
|
| 10 |
|
| 11 |
try:
|
| 12 |
result = tts_pipe(text)
|
|
|
|
| 13 |
sampling_rate = result["sampling_rate"]
|
| 14 |
audio_data = result["audio"]
|
| 15 |
return (sampling_rate, audio_data.astype(np.float32)), "Голос згенеровано успішно!"
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
+
return None, f"Помилка: {str(e)}"
|
| 18 |
|
| 19 |
with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
| 20 |
+
gr.Markdown("#Озвучка задач для учнів")
|
|
|
|
| 21 |
with gr.Row():
|
| 22 |
with gr.Column():
|
| 23 |
+
text_input = gr.Textbox(label="Текст", lines=4)
|
| 24 |
+
btn = gr.Button("Озвучити", variant="primary")
|
| 25 |
with gr.Column():
|
| 26 |
+
audio_out = gr.Audio(label="Слухати")
|
| 27 |
status = gr.Label(label="Статус")
|
| 28 |
|
| 29 |
btn.click(generate_audio, inputs=text_input, outputs=[audio_out, status])
|
| 30 |
|
| 31 |
+
demo.launch()
|