jonathanagustin commited on
Commit
45f3b08
1 Parent(s): 5ff3e3d

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tempfile
3
+ import openai
4
+
5
+ def tts(input_text, model, voice, api_key):
6
+ openai.api_key = api_key
7
+ response = openai.audio.speech.create(
8
+ input=input_text,
9
+ voice=voice,
10
+ model=model
11
+ )
12
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
13
+ temp_file.write(response.content)
14
+ temp_file_path = temp_file.name
15
+ return temp_file_path
16
+
17
+ model_options = ["tts-1", "tts-1-hd"]
18
+ voice_options = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
19
+
20
+ with gr.Blocks(analytics_enabled=False) as demo:
21
+ with gr.Row():
22
+ with gr.Column(scale=1):
23
+ api_key_input = gr.Textbox(label="API Key", type="password")
24
+ model_dropdown = gr.Dropdown(choices=model_options, label="Model", value="tts-1-hd")
25
+ voice_dropdown = gr.Dropdown(choices=voice_options, label="Voice Options", value="echo")
26
+ with gr.Column(scale=2):
27
+ input_textbox = gr.Textbox(
28
+ label="Input Text",
29
+ lines=10,
30
+ placeholder="Type your text here..."
31
+ )
32
+ submit_button = gr.Button("Text-to-Speech", variant="primary")
33
+ with gr.Column(scale=1):
34
+ output_audio = gr.Audio(label="Output Audio")
35
+
36
+ def on_convert_click(input_text, model, voice, api_key):
37
+ return tts(input_text, model, voice, api_key)
38
+
39
+ submit_button.click(
40
+ fn=on_convert_click,
41
+ inputs=[input_textbox, model_dropdown, voice_dropdown, api_key_input],
42
+ outputs=output_audio
43
+ )
44
+
45
+ input_textbox.submit(
46
+ fn=on_convert_click,
47
+ inputs=[input_textbox, model_dropdown, voice_dropdown, api_key_input],
48
+ outputs=output_audio
49
+ )
50
+
51
+ demo.launch(debug=True, share=True)