Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,15 +10,17 @@ client = Client("ResembleAI/Chatterbox", hf_token)
|
|
10 |
|
11 |
# Define the function to call the model and return the generated audio file
|
12 |
def generate_tts_audio(text_input, audio_prompt_url, exaggeration_input, temperature_input, seed_num_input, cfgw_input):
|
13 |
-
print("sending request")
|
14 |
-
if audio_prompt_url.strip():
|
15 |
-
audio_prompt = handle_file(audio_prompt_url)
|
16 |
-
else:
|
17 |
-
audio_prompt = None
|
18 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
result = client.predict(
|
20 |
text_input=text_input,
|
21 |
-
audio_prompt_path_input=
|
22 |
exaggeration_input=exaggeration_input,
|
23 |
temperature_input=temperature_input,
|
24 |
seed_num_input=seed_num_input,
|
@@ -26,11 +28,17 @@ def generate_tts_audio(text_input, audio_prompt_url, exaggeration_input, tempera
|
|
26 |
api_name="/generate_tts_audio"
|
27 |
)
|
28 |
print("API Result:", result)
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
except Exception as e:
|
31 |
print(f"An error occurred: {e}")
|
32 |
return None
|
33 |
|
|
|
34 |
# Create the Gradio interface
|
35 |
interface = gr.Interface(
|
36 |
fn=generate_tts_audio,
|
|
|
10 |
|
11 |
# Define the function to call the model and return the generated audio file
|
12 |
def generate_tts_audio(text_input, audio_prompt_url, exaggeration_input, temperature_input, seed_num_input, cfgw_input):
|
|
|
|
|
|
|
|
|
|
|
13 |
try:
|
14 |
+
print("sending request")
|
15 |
+
# Only process the audio prompt if the field is not empty
|
16 |
+
if audio_prompt_url and audio_prompt_url.strip():
|
17 |
+
audio_prompt = handle_file(audio_prompt_url)
|
18 |
+
else:
|
19 |
+
audio_prompt = None # This is the KEY change
|
20 |
+
|
21 |
result = client.predict(
|
22 |
text_input=text_input,
|
23 |
+
audio_prompt_path_input=audio_prompt,
|
24 |
exaggeration_input=exaggeration_input,
|
25 |
temperature_input=temperature_input,
|
26 |
seed_num_input=seed_num_input,
|
|
|
28 |
api_name="/generate_tts_audio"
|
29 |
)
|
30 |
print("API Result:", result)
|
31 |
+
audio_path = result.get('filepath', None)
|
32 |
+
if audio_path and os.path.exists(audio_path) and os.path.getsize(audio_path) > 1000:
|
33 |
+
return audio_path
|
34 |
+
else:
|
35 |
+
print("No valid audio generated.")
|
36 |
+
return None # Or return "No valid audio generated."
|
37 |
except Exception as e:
|
38 |
print(f"An error occurred: {e}")
|
39 |
return None
|
40 |
|
41 |
+
|
42 |
# Create the Gradio interface
|
43 |
interface = gr.Interface(
|
44 |
fn=generate_tts_audio,
|