umertayyeb commited on
Commit
9f382fd
·
verified ·
1 Parent(s): 95b78a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -22
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
- # Example text input, audio prompt URL, and other parameters
11
- text_input = "Now let's make my mum's favourite. So three mars bars into the pan. Then we add the tuna and just stir for a bit, just let the chocolate and fish infuse. A sprinkle of olive oil and some tomato ketchup. Now smell that. Oh boy this is going to be incredible."
12
- audio_prompt_url = 'https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav'
13
- exaggeration_input = 0.5
14
- temperature_input = 0.8
15
- seed_num_input = 0
16
- cfgw_input = 0.5
 
 
 
 
 
 
 
 
 
17
 
18
- # Use try-except to handle any errors that might occur during the prediction
19
- try:
20
- result = client.predict(
21
- text_input=text_input,
22
- audio_prompt_path_input=handle_file(audio_prompt_url),
23
- exaggeration_input=exaggeration_input,
24
- temperature_input=temperature_input,
25
- seed_num_input=seed_num_input,
26
- cfgw_input=cfgw_input,
27
- api_name="/generate_tts_audio"
28
- )
29
- print(result) # Print the result (filepath to generated audio)
30
- except Exception as e:
31
- # Handle the error by printing the exception message
32
- print(f"An error occurred: {e}")
 
 
 
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()