Spaces:
Running
on
Zero
Running
on
Zero
Try fix UI bug
Browse files
app.py
CHANGED
@@ -2,13 +2,11 @@ import gradio as gr
|
|
2 |
import outetts
|
3 |
import json
|
4 |
import tempfile
|
5 |
-
import os
|
6 |
-
from typing import Optional, Dict, Any, List, Tuple
|
7 |
|
8 |
# Available OuteTTS models based on the documentation
|
9 |
MODELS = {v.value: v for _, v in outetts.Models.__members__.items()}
|
10 |
|
11 |
-
def initialize_interface(model_name: str)
|
12 |
"""Initialize the OuteTTS interface with selected model."""
|
13 |
model = MODELS[model_name]
|
14 |
|
@@ -23,146 +21,86 @@ def initialize_interface(model_name: str) -> Any:
|
|
23 |
interface = outetts.Interface(config=config)
|
24 |
return interface
|
25 |
|
26 |
-
def
|
27 |
-
"""Create
|
28 |
-
if interface_state is None:
|
29 |
-
raise gr.Error("Please select a model first")
|
30 |
-
|
31 |
if audio_file is None:
|
32 |
raise gr.Error("Please upload an audio file")
|
33 |
|
|
|
|
|
|
|
34 |
# Create speaker profile from audio
|
35 |
-
speaker =
|
36 |
|
37 |
# Convert speaker dict to formatted JSON
|
38 |
speaker_json = json.dumps(speaker, indent=2, ensure_ascii=False)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
raise gr.Error("Please create a speaker first")
|
51 |
-
|
52 |
-
if not text.strip():
|
53 |
-
raise gr.Error("Please enter text to generate")
|
54 |
-
|
55 |
-
# Generate audio
|
56 |
-
output = interface_state.generate(
|
57 |
-
config=outetts.GenerationConfig(
|
58 |
-
text=text,
|
59 |
-
speaker=speaker_state,
|
60 |
-
sampler_config=outetts.SamplerConfig(
|
61 |
-
temperature=temperature
|
62 |
)
|
63 |
)
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
68 |
-
output.save(f.name)
|
69 |
-
return f.name
|
70 |
|
71 |
# Create the Gradio interface
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
)
|
119 |
-
|
120 |
-
with gr.Row():
|
121 |
-
with gr.Column():
|
122 |
-
gr.Markdown("## 🎧 Test Audio Generation")
|
123 |
-
test_text = gr.Textbox(
|
124 |
-
label="Test Text",
|
125 |
-
placeholder="Enter text to generate speech...",
|
126 |
-
lines=3,
|
127 |
-
value="Hello, this is a test of the OuteTTS speaker profile."
|
128 |
-
)
|
129 |
-
|
130 |
-
temperature_slider = gr.Slider(
|
131 |
-
minimum=0.1,
|
132 |
-
maximum=1.0,
|
133 |
-
step=0.1,
|
134 |
-
value=0.4,
|
135 |
-
label="Temperature",
|
136 |
-
info="Controls randomness in generation"
|
137 |
-
)
|
138 |
-
|
139 |
-
generate_button = gr.Button("Generate Sample Audio", variant="primary")
|
140 |
-
sample_audio = gr.Audio(label="Generated Audio", interactive=False)
|
141 |
-
|
142 |
-
# Event handlers
|
143 |
-
# Initialize default model on page load
|
144 |
-
demo.load(
|
145 |
-
fn=initialize_interface,
|
146 |
-
inputs=[model_dropdown],
|
147 |
-
outputs=[interface_state]
|
148 |
-
)
|
149 |
-
|
150 |
-
model_dropdown.change(
|
151 |
-
fn=initialize_interface,
|
152 |
-
inputs=[model_dropdown],
|
153 |
-
outputs=[interface_state]
|
154 |
-
)
|
155 |
-
|
156 |
-
create_button.click(
|
157 |
-
fn=create_speaker_from_audio,
|
158 |
-
inputs=[audio_upload, interface_state],
|
159 |
-
outputs=[speaker_json, speaker_state]
|
160 |
-
)
|
161 |
-
|
162 |
-
generate_button.click(
|
163 |
-
fn=generate_sample_audio,
|
164 |
-
inputs=[test_text, temperature_slider, interface_state, speaker_state],
|
165 |
-
outputs=[sample_audio]
|
166 |
-
)
|
167 |
|
168 |
demo.launch()
|
|
|
2 |
import outetts
|
3 |
import json
|
4 |
import tempfile
|
|
|
|
|
5 |
|
6 |
# Available OuteTTS models based on the documentation
|
7 |
MODELS = {v.value: v for _, v in outetts.Models.__members__.items()}
|
8 |
|
9 |
+
def initialize_interface(model_name: str):
|
10 |
"""Initialize the OuteTTS interface with selected model."""
|
11 |
model = MODELS[model_name]
|
12 |
|
|
|
21 |
interface = outetts.Interface(config=config)
|
22 |
return interface
|
23 |
|
24 |
+
def create_speaker_and_generate(model_name, audio_file, test_text="", temperature=0.4):
|
25 |
+
"""Create speaker from audio and optionally generate test audio."""
|
|
|
|
|
|
|
26 |
if audio_file is None:
|
27 |
raise gr.Error("Please upload an audio file")
|
28 |
|
29 |
+
# Initialize model
|
30 |
+
interface = initialize_interface(model_name)
|
31 |
+
|
32 |
# Create speaker profile from audio
|
33 |
+
speaker = interface.create_speaker(audio_file)
|
34 |
|
35 |
# Convert speaker dict to formatted JSON
|
36 |
speaker_json = json.dumps(speaker, indent=2, ensure_ascii=False)
|
37 |
|
38 |
+
# Generate test audio if text is provided
|
39 |
+
generated_audio = None
|
40 |
+
if test_text and test_text.strip():
|
41 |
+
output = interface.generate(
|
42 |
+
config=outetts.GenerationConfig(
|
43 |
+
text=test_text,
|
44 |
+
speaker=speaker,
|
45 |
+
sampler_config=outetts.SamplerConfig(
|
46 |
+
temperature=temperature
|
47 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
)
|
49 |
)
|
50 |
+
|
51 |
+
# Save to temporary file
|
52 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
53 |
+
output.save(f.name)
|
54 |
+
generated_audio = f.name
|
55 |
|
56 |
+
return speaker_json, generated_audio
|
|
|
|
|
|
|
57 |
|
58 |
# Create the Gradio interface
|
59 |
+
demo = gr.Interface(
|
60 |
+
fn=create_speaker_and_generate,
|
61 |
+
inputs=[
|
62 |
+
gr.Dropdown(
|
63 |
+
choices=list(MODELS.keys()),
|
64 |
+
value=list(MODELS.keys())[-1],
|
65 |
+
label="Select OuteTTS Model",
|
66 |
+
info="Choose the model variant to use"
|
67 |
+
),
|
68 |
+
gr.Audio(
|
69 |
+
label="Upload Reference Audio",
|
70 |
+
type="filepath",
|
71 |
+
sources=["upload", "microphone"]
|
72 |
+
),
|
73 |
+
gr.Textbox(
|
74 |
+
label="Test Text (Optional)",
|
75 |
+
placeholder="Enter text to generate speech (leave empty to only create speaker profile)...",
|
76 |
+
lines=3,
|
77 |
+
value="Hello, this is a test of the OuteTTS speaker profile."
|
78 |
+
),
|
79 |
+
gr.Slider(
|
80 |
+
minimum=0.1,
|
81 |
+
maximum=1.0,
|
82 |
+
step=0.1,
|
83 |
+
value=0.4,
|
84 |
+
label="Temperature",
|
85 |
+
info="Controls randomness in generation"
|
86 |
+
)
|
87 |
+
],
|
88 |
+
outputs=[
|
89 |
+
gr.Textbox(
|
90 |
+
label="Speaker Profile (JSON)",
|
91 |
+
lines=15,
|
92 |
+
max_lines=20,
|
93 |
+
show_copy_button=True
|
94 |
+
),
|
95 |
+
gr.Audio(
|
96 |
+
label="Generated Test Audio (if text provided)",
|
97 |
+
type="filepath"
|
98 |
+
)
|
99 |
+
],
|
100 |
+
title="🎙️ OuteTTS Speaker Creator",
|
101 |
+
description="Create and manage speaker profiles for OuteTTS text-to-speech synthesis. Upload audio to create a speaker profile, and optionally provide test text to generate sample audio.",
|
102 |
+
theme=gr.themes.Soft(),
|
103 |
+
examples=None
|
104 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
demo.launch()
|