shukdevdatta123 commited on
Commit
358c7e6
·
verified ·
1 Parent(s): 2962129

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -24
app.py CHANGED
@@ -157,7 +157,7 @@ for v in CHOICES.values():
157
 
158
  TOKEN_NOTE = '''
159
  💡 Customize pronunciation with Markdown link syntax and /slashes/ like `[Kokoro](/kˈOkəɹO/)`
160
- 💬 To adjust intonation, try punctuation `;:,.!?—…"()“”`
161
  ⬇️ Lower stress `[1 level](-1)` or `[2 levels](-2)`
162
  ⬆️ Raise stress 1 level `[or](+2)` 2 levels (only works on less stressed, usually short words)
163
  '''
@@ -165,36 +165,18 @@ TOKEN_NOTE = '''
165
  with gr.Blocks() as generate_tab:
166
  out_audio = gr.Audio(label='Output Audio', interactive=False, streaming=False, autoplay=True)
167
  generate_btn = gr.Button('Generate', variant='primary')
168
-
169
- # Commenting out the Output Tokens and Stream Tab sections
170
- '''
171
  with gr.Accordion('Output Tokens', open=True):
172
  out_ps = gr.Textbox(interactive=False, show_label=False, info='Tokens used to generate the audio, up to 510 context length.')
173
  tokenize_btn = gr.Button('Tokenize', variant='secondary')
174
  gr.Markdown(TOKEN_NOTE)
175
  predict_btn = gr.Button('Predict', variant='secondary', visible=False)
176
 
177
- STREAM_NOTE = ['⚠️ There is an unknown Gradio bug that might yield no audio the first time you click `Stream`.']
178
- if CHAR_LIMIT is not None:
179
- STREAM_NOTE.append(f'✂️ Each stream is capped at {CHAR_LIMIT} characters.')
180
- STREAM_NOTE.append('🚀 Want more characters? You can [use Kokoro directly](https://huggingface.co/hexgrad/Kokoro-82M#usage) or duplicate this space:')
181
- STREAM_NOTE = '\n\n'.join(STREAM_NOTE)
182
-
183
- with gr.Blocks() as stream_tab:
184
- out_stream = gr.Audio(label='Output Audio Stream', interactive=False, streaming=True, autoplay=True)
185
- with gr.Row():
186
- stream_btn = gr.Button('Stream', variant='primary')
187
- stop_btn = gr.Button('Stop', variant='stop')
188
- with gr.Accordion('Note', open=True):
189
- gr.Markdown(STREAM_NOTE)
190
- gr.DuplicateButton()
191
- '''
192
-
193
  BANNER_TEXT = '''
194
  [***Kokoro*** **is an open-weight TTS model with 82 million parameters.**](https://huggingface.co/hexgrad/Kokoro-82M)
195
  As of January 31st, 2025, Kokoro was the most-liked [**TTS model**](https://huggingface.co/models?pipeline_tag=text-to-speech&sort=likes) and the most-liked [**TTS space**](https://huggingface.co/spaces?sort=likes&search=tts) on Hugging Face.
196
  This demo only showcases English, but you can directly use the model to access other languages.
197
  '''
 
198
  API_OPEN = os.getenv('SPACE_ID') != 'hexgrad/Kokoro-TTS'
199
  API_NAME = None if API_OPEN else False
200
  with gr.Blocks() as app:
@@ -215,11 +197,11 @@ with gr.Blocks() as app:
215
  speed = gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label='Speed')
216
  random_btn = gr.Button('Random Text', variant='secondary')
217
  with gr.Column():
218
- # Only keeping the Generate tab active
219
- generate_btn.click(fn=generate_first, inputs=[text, voice, speed, use_gpu], outputs=[out_audio, out_ps], api_name=API_NAME)
220
- tokenize_btn.click(fn=tokenize_first, inputs=[text, voice], outputs=[out_ps], api_name=API_NAME)
221
-
222
  random_btn.click(fn=get_random_text, inputs=[voice], outputs=[text], api_name=API_NAME)
 
 
 
223
 
224
  if __name__ == '__main__':
225
  app.queue(api_open=API_OPEN).launch(show_api=API_OPEN, ssr_mode=True)
 
157
 
158
  TOKEN_NOTE = '''
159
  💡 Customize pronunciation with Markdown link syntax and /slashes/ like `[Kokoro](/kˈOkəɹO/)`
160
+ 💬 To adjust intonation, try punctuation `;:,.!?—…"()“”` or stress `ˈ` and `ˌ`
161
  ⬇️ Lower stress `[1 level](-1)` or `[2 levels](-2)`
162
  ⬆️ Raise stress 1 level `[or](+2)` 2 levels (only works on less stressed, usually short words)
163
  '''
 
165
  with gr.Blocks() as generate_tab:
166
  out_audio = gr.Audio(label='Output Audio', interactive=False, streaming=False, autoplay=True)
167
  generate_btn = gr.Button('Generate', variant='primary')
 
 
 
168
  with gr.Accordion('Output Tokens', open=True):
169
  out_ps = gr.Textbox(interactive=False, show_label=False, info='Tokens used to generate the audio, up to 510 context length.')
170
  tokenize_btn = gr.Button('Tokenize', variant='secondary')
171
  gr.Markdown(TOKEN_NOTE)
172
  predict_btn = gr.Button('Predict', variant='secondary', visible=False)
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  BANNER_TEXT = '''
175
  [***Kokoro*** **is an open-weight TTS model with 82 million parameters.**](https://huggingface.co/hexgrad/Kokoro-82M)
176
  As of January 31st, 2025, Kokoro was the most-liked [**TTS model**](https://huggingface.co/models?pipeline_tag=text-to-speech&sort=likes) and the most-liked [**TTS space**](https://huggingface.co/spaces?sort=likes&search=tts) on Hugging Face.
177
  This demo only showcases English, but you can directly use the model to access other languages.
178
  '''
179
+
180
  API_OPEN = os.getenv('SPACE_ID') != 'hexgrad/Kokoro-TTS'
181
  API_NAME = None if API_OPEN else False
182
  with gr.Blocks() as app:
 
197
  speed = gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label='Speed')
198
  random_btn = gr.Button('Random Text', variant='secondary')
199
  with gr.Column():
200
+ gr.TabbedInterface([generate_tab], ['Generate'])
 
 
 
201
  random_btn.click(fn=get_random_text, inputs=[voice], outputs=[text], api_name=API_NAME)
202
+ generate_btn.click(fn=generate_first, inputs=[text, voice, speed, use_gpu], outputs=[out_audio, out_ps], api_name=API_NAME)
203
+ tokenize_btn.click(fn=tokenize_first, inputs=[text, voice], outputs=[out_ps], api_name=API_NAME)
204
+ predict_btn.click(fn=predict, inputs=[text, voice, speed], outputs=[out_audio], api_name=API_NAME)
205
 
206
  if __name__ == '__main__':
207
  app.queue(api_open=API_OPEN).launch(show_api=API_OPEN, ssr_mode=True)