Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from gradio_client import Client, handle_file
|
2 |
import os
|
|
|
3 |
|
4 |
# Get Hugging Face token from environment variable
|
5 |
hf_token = os.getenv("your_huggingface_token") # Make sure this is set in your environment
|
@@ -7,26 +8,37 @@ hf_token = os.getenv("your_huggingface_token") # Make sure this is set in your
|
|
7 |
# Initialize the Gradio client with the token
|
8 |
client = Client("ResembleAI/Chatterbox", hf_token)
|
9 |
|
10 |
-
#
|
11 |
-
text_input
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
1 |
from gradio_client import Client, handle_file
|
2 |
import os
|
3 |
+
import gradio as gr
|
4 |
|
5 |
# Get Hugging Face token from environment variable
|
6 |
hf_token = os.getenv("your_huggingface_token") # Make sure this is set in your environment
|
|
|
8 |
# Initialize the Gradio client with the token
|
9 |
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 |
+
try:
|
14 |
+
result = client.predict(
|
15 |
+
text_input=text_input,
|
16 |
+
audio_prompt_path_input=handle_file(audio_prompt_url),
|
17 |
+
exaggeration_input=exaggeration_input,
|
18 |
+
temperature_input=temperature_input,
|
19 |
+
seed_num_input=seed_num_input,
|
20 |
+
cfgw_input=cfgw_input,
|
21 |
+
api_name="/generate_tts_audio"
|
22 |
+
)
|
23 |
+
return result['filepath'] # Return the filepath to the generated audio
|
24 |
+
except Exception as e:
|
25 |
+
# Handle errors and display them to the user
|
26 |
+
return f"An error occurred: {e}"
|
27 |
|
28 |
+
# Create the Gradio interface
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=generate_tts_audio,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(label="Text to Synthesize", placeholder="Enter your text here..."),
|
33 |
+
gr.Textbox(label="Audio Prompt URL", placeholder="Enter the URL of the audio prompt (Optional)", default='https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav'),
|
34 |
+
gr.Slider(minimum=0, maximum=1, default=0.5, label="Exaggeration"),
|
35 |
+
gr.Slider(minimum=0, maximum=1, default=0.8, label="Temperature"),
|
36 |
+
gr.Number(label="Seed Number", value=0),
|
37 |
+
gr.Slider(minimum=0, maximum=1, default=0.5, label="CFG/Pace")
|
38 |
+
],
|
39 |
+
outputs=gr.Audio(label="Generated Audio")
|
40 |
+
)
|
41 |
+
|
42 |
+
# Launch the Gradio interface
|
43 |
+
if __name__ == "__main__":
|
44 |
+
interface.launch()
|