Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import spaces
|
|
2 |
from kokoro import KModel, KPipeline
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
-
import random
|
6 |
import torch
|
7 |
|
8 |
IS_DUPLICATE = not os.getenv('SPACE_ID', '').startswith('hexgrad/')
|
@@ -71,15 +70,6 @@ def generate_all(text, voice='af_heart', speed=1, use_gpu=CUDA_AVAILABLE):
|
|
71 |
raise gr.Error(e)
|
72 |
yield 24000, audio.numpy()
|
73 |
|
74 |
-
random_texts = {}
|
75 |
-
for lang in ['en']:
|
76 |
-
with open(f'{lang}.txt', 'r') as r:
|
77 |
-
random_texts[lang] = [line.strip() for line in r]
|
78 |
-
|
79 |
-
def get_random_text(voice):
|
80 |
-
lang = dict(a='en', b='en')[voice[0]]
|
81 |
-
return random.choice(random_texts[lang])
|
82 |
-
|
83 |
CHOICES = {
|
84 |
'๐บ๐ธ ๐บ Heart โค๏ธ': 'af_heart',
|
85 |
'๐บ๐ธ ๐บ Bella ๐ฅ': 'af_bella',
|
@@ -168,10 +158,8 @@ with gr.Blocks() as app:
|
|
168 |
interactive=CUDA_AVAILABLE
|
169 |
)
|
170 |
speed = gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label='Speed')
|
171 |
-
random_btn = gr.Button('Random Text', variant='secondary')
|
172 |
with gr.Column():
|
173 |
gr.TabbedInterface([generate_tab, stream_tab], ['Generate', 'Stream'])
|
174 |
-
random_btn.click(fn=get_random_text, inputs=[voice], outputs=[text], api_name=API_NAME)
|
175 |
generate_btn.click(fn=generate_first, inputs=[text, voice, speed, use_gpu], outputs=[out_audio, out_ps], api_name=API_NAME)
|
176 |
tokenize_btn.click(fn=tokenize_first, inputs=[text, voice], outputs=[out_ps], api_name=API_NAME)
|
177 |
stream_event = stream_btn.click(fn=generate_all, inputs=[text, voice, speed, use_gpu], outputs=[out_stream], api_name=API_NAME)
|
|
|
2 |
from kokoro import KModel, KPipeline
|
3 |
import gradio as gr
|
4 |
import os
|
|
|
5 |
import torch
|
6 |
|
7 |
IS_DUPLICATE = not os.getenv('SPACE_ID', '').startswith('hexgrad/')
|
|
|
70 |
raise gr.Error(e)
|
71 |
yield 24000, audio.numpy()
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
CHOICES = {
|
74 |
'๐บ๐ธ ๐บ Heart โค๏ธ': 'af_heart',
|
75 |
'๐บ๐ธ ๐บ Bella ๐ฅ': 'af_bella',
|
|
|
158 |
interactive=CUDA_AVAILABLE
|
159 |
)
|
160 |
speed = gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label='Speed')
|
|
|
161 |
with gr.Column():
|
162 |
gr.TabbedInterface([generate_tab, stream_tab], ['Generate', 'Stream'])
|
|
|
163 |
generate_btn.click(fn=generate_first, inputs=[text, voice, speed, use_gpu], outputs=[out_audio, out_ps], api_name=API_NAME)
|
164 |
tokenize_btn.click(fn=tokenize_first, inputs=[text, voice], outputs=[out_ps], api_name=API_NAME)
|
165 |
stream_event = stream_btn.click(fn=generate_all, inputs=[text, voice, speed, use_gpu], outputs=[out_stream], api_name=API_NAME)
|