Spaces:
Sleeping
Sleeping
added bring your own key
Browse files
app.py
CHANGED
@@ -3,12 +3,10 @@ import os
|
|
3 |
import tempfile
|
4 |
from openai import OpenAI
|
5 |
|
6 |
-
# Set an environment variable for key
|
7 |
-
os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
12 |
response = client.audio.speech.create(
|
13 |
model=model, #"tts-1","tts-1-hd"
|
14 |
voice=voice, #'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
|
@@ -28,11 +26,12 @@ def tts(text, model, voice):
|
|
28 |
with gr.Blocks() as demo:
|
29 |
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
30 |
gr.HTML("You can also access the Streaming demo for OpenAI TTS by clicking this <a href='https://huggingface.co/spaces/ysharma/OpenAI_TTS_Streaming'>Gradio demo link</a>")
|
31 |
-
with gr.Row():
|
|
|
32 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
|
33 |
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='alloy')
|
34 |
|
35 |
-
text = gr.Textbox(label="Input text", placeholder="
|
36 |
btn = gr.Button("Text-To-Speech")
|
37 |
output_audio = gr.Audio(label="Speech Output")
|
38 |
|
|
|
3 |
import tempfile
|
4 |
from openai import OpenAI
|
5 |
|
|
|
|
|
6 |
|
7 |
+
def tts(text, model, voice, api_key):
|
8 |
|
9 |
+
client = OpenAI(api_key=api_key)
|
10 |
response = client.audio.speech.create(
|
11 |
model=model, #"tts-1","tts-1-hd"
|
12 |
voice=voice, #'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
|
|
|
26 |
with gr.Blocks() as demo:
|
27 |
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
28 |
gr.HTML("You can also access the Streaming demo for OpenAI TTS by clicking this <a href='https://huggingface.co/spaces/ysharma/OpenAI_TTS_Streaming'>Gradio demo link</a>")
|
29 |
+
with gr.Row(variant='panel'):
|
30 |
+
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS demo')
|
31 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
|
32 |
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='alloy')
|
33 |
|
34 |
+
text = gr.Textbox(label="Input text", placeholder="Enter your text and then click on the 'Text-To-Speech' button, or simply press the Enter key.")
|
35 |
btn = gr.Button("Text-To-Speech")
|
36 |
output_audio = gr.Audio(label="Speech Output")
|
37 |
|