Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,20 +5,15 @@ from openai import OpenAI
|
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
|
| 8 |
-
def create_header(api_key):
|
| 9 |
-
return {
|
| 10 |
-
'Authorization': f'Bearer {api_key}',
|
| 11 |
-
'Content-Type': 'application/json'
|
| 12 |
-
}
|
| 13 |
|
| 14 |
-
def tts(text, model, voice, api_key
|
| 15 |
if api_key == '':
|
| 16 |
raise gr.Error('Please enter your OpenAI API Key')
|
| 17 |
else:
|
| 18 |
try:
|
| 19 |
-
headers =
|
| 20 |
-
|
| 21 |
-
url =
|
| 22 |
input_text = text
|
| 23 |
query = {
|
| 24 |
"model":model,# "tts-1","tts-1-hd"
|
|
@@ -45,18 +40,18 @@ def tts(text, model, voice, api_key,url):
|
|
| 45 |
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
|
|
|
| 48 |
#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>")
|
| 49 |
with gr.Row(variant='panel'):
|
| 50 |
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS demo')
|
| 51 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
|
| 52 |
-
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='
|
| 53 |
-
url = gr.Textbox(label="URL", placeholder="Enter your URL and then click on the 'Text-To-Speech' button, or simply press the Enter key.", value='https://openkey.cloud/v1/audio/speech')
|
| 54 |
|
| 55 |
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.")
|
| 56 |
btn = gr.Button("Text-To-Speech")
|
| 57 |
output_audio = gr.Audio(label="Speech Output")
|
| 58 |
|
| 59 |
-
text.submit(fn=tts, inputs=[text, model, voice, api_key
|
| 60 |
-
btn.click(fn=tts, inputs=[text, model, voice, api_key
|
| 61 |
|
| 62 |
demo.launch()
|
|
|
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def tts(text, model, voice, api_key):
|
| 10 |
if api_key == '':
|
| 11 |
raise gr.Error('Please enter your OpenAI API Key')
|
| 12 |
else:
|
| 13 |
try:
|
| 14 |
+
headers = {'Authorization': f'Bearer sk-ztrcLG06AudTIErn3OsNbxmtXatSL7AHCokpnCwk6TvgvYwI',
|
| 15 |
+
'Content-Type':'application/json'}
|
| 16 |
+
url = "https://openkey.cloud/v1/audio/speech"
|
| 17 |
input_text = text
|
| 18 |
query = {
|
| 19 |
"model":model,# "tts-1","tts-1-hd"
|
|
|
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
|
| 43 |
+
gr.Markdown("This demo uses the OpenAI Text-To-Speech API to generate speech from text. You get free API key from https://faucet.openkey.cloud/")
|
| 44 |
#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>")
|
| 45 |
with gr.Row(variant='panel'):
|
| 46 |
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS demo')
|
| 47 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
|
| 48 |
+
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='nova')
|
|
|
|
| 49 |
|
| 50 |
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.")
|
| 51 |
btn = gr.Button("Text-To-Speech")
|
| 52 |
output_audio = gr.Audio(label="Speech Output")
|
| 53 |
|
| 54 |
+
text.submit(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
|
| 55 |
+
btn.click(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
|
| 56 |
|
| 57 |
demo.launch()
|