MAZALA2024 commited on
Commit
a487ae6
1 Parent(s): 9f55e76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -27
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
- import base64
3
- import numpy as np
4
- from scipy.io import wavfile
5
- from voice_processing import parallel_tts, get_model_names, voice_mapping
6
- from io import BytesIO
7
  import asyncio
8
  import logging
 
 
 
 
9
 
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
11
  logger = logging.getLogger(__name__)
@@ -18,8 +18,7 @@ async def convert_tts(model_name, tts_text, selected_voice, slang_rate, use_uplo
18
 
19
  voice_upload_file = None
20
  if use_uploaded_voice and voice_upload is not None:
21
- with open(voice_upload.name, 'rb') as f:
22
- voice_upload_file = f.read()
23
 
24
  # Create task for parallel processing
25
  task = (
@@ -27,7 +26,7 @@ async def convert_tts(model_name, tts_text, selected_voice, slang_rate, use_uplo
27
  )
28
 
29
  # Asynchronous call to your tts processing function using parallel processing
30
- result = await asyncio.get_event_loop().run_in_executor(None, parallel_tts, [task])
31
  info, _, (tgt_sr, audio_output) = result[0]
32
 
33
  return {"info": info}, (tgt_sr, audio_output)
@@ -43,23 +42,26 @@ def get_voices():
43
  return list(voice_mapping.keys())
44
 
45
  # Initialize the Gradio interface
46
- iface = gr.Interface(
47
- fn=convert_tts,
48
- inputs=[
49
- gr.Dropdown(choices=get_models(), label="Model", interactive=True),
50
- gr.Textbox(label="Text", placeholder="Enter text here"),
51
- gr.Dropdown(choices=get_voices(), label="Voice", interactive=True),
52
- gr.Slider(minimum=0, maximum=1, step=0.01, label="Slang Rate"),
53
- gr.Checkbox(label="Use Uploaded Voice"),
54
- gr.File(label="Voice File")
55
- ],
56
- outputs=[
57
- gr.JSON(label="Info"),
58
- gr.Audio(label="Generated Audio", type="numpy")
59
- ],
60
- title="Text-to-Speech Conversion"
61
- ).queue(concurrency_count=16) # Adjust based on your server's capacity
 
 
 
 
 
62
 
63
- # Launch the interface
64
- if __name__ == "__main__":
65
- iface.launch(debug=True)
 
1
  import gradio as gr
2
+ import sys
 
 
 
 
3
  import asyncio
4
  import logging
5
+ from voice_processing import parallel_tts, get_model_names, voice_mapping
6
+
7
+ print(f"Python version: {sys.version}")
8
+ print(f"Gradio version: {gr.__version__}")
9
 
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
11
  logger = logging.getLogger(__name__)
 
18
 
19
  voice_upload_file = None
20
  if use_uploaded_voice and voice_upload is not None:
21
+ voice_upload_file = voice_upload
 
22
 
23
  # Create task for parallel processing
24
  task = (
 
26
  )
27
 
28
  # Asynchronous call to your tts processing function using parallel processing
29
+ result = await asyncio.to_thread(parallel_tts, [task])
30
  info, _, (tgt_sr, audio_output) = result[0]
31
 
32
  return {"info": info}, (tgt_sr, audio_output)
 
42
  return list(voice_mapping.keys())
43
 
44
  # Initialize the Gradio interface
45
+ with gr.Blocks() as iface:
46
+ with gr.Row():
47
+ with gr.Column():
48
+ model_name = gr.Dropdown(choices=get_models(), label="Model", interactive=True)
49
+ tts_text = gr.Textbox(label="Text", placeholder="Enter text here")
50
+ selected_voice = gr.Dropdown(choices=get_voices(), label="Voice", interactive=True)
51
+ slang_rate = gr.Slider(minimum=0, maximum=1, step=0.01, label="Slang Rate")
52
+ use_uploaded_voice = gr.Checkbox(label="Use Uploaded Voice")
53
+ voice_upload = gr.File(label="Voice File")
54
+ submit_btn = gr.Button("Generate Audio")
55
+
56
+ with gr.Column():
57
+ info_output = gr.JSON(label="Info")
58
+ audio_output = gr.Audio(label="Generated Audio", type="numpy")
59
+
60
+ submit_btn.click(
61
+ fn=convert_tts,
62
+ inputs=[model_name, tts_text, selected_voice, slang_rate, use_uploaded_voice, voice_upload],
63
+ outputs=[info_output, audio_output],
64
+ api_name="convert_tts"
65
+ )
66
 
67
+ iface.launch()