Spaces:
Paused
Paused
Gradio 6.29: theme to launch; add gpt-4o-mini-tts
Browse files- README.md +1 -1
- app.py +50 -50
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 📊
|
|
| 4 |
colorFrom: pink
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 4 |
colorFrom: pink
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -1,50 +1,50 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import tempfile
|
| 4 |
-
import time
|
| 5 |
-
from openai import OpenAI
|
| 6 |
-
|
| 7 |
-
def tts(text, model, voice, api_key):
|
| 8 |
-
if api_key == '':
|
| 9 |
-
raise gr.Error('Please enter your OpenAI API Key')
|
| 10 |
-
else:
|
| 11 |
-
try:
|
| 12 |
-
client = OpenAI(api_key=api_key)
|
| 13 |
-
|
| 14 |
-
response = client.audio.speech.create(
|
| 15 |
-
model=model, # "tts-1","tts-1-hd"
|
| 16 |
-
voice=voice, # 'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
|
| 17 |
-
input=text,
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
except Exception as error:
|
| 21 |
-
# Handle any exception that occurs
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# Create a temp file to save the audio
|
| 26 |
-
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
| 27 |
-
temp_file.write(response.content)
|
| 28 |
-
|
| 29 |
-
# Get the file path of the temp file
|
| 30 |
-
temp_file_path = temp_file.name
|
| 31 |
-
|
| 32 |
-
return temp_file_path
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
with gr.Blocks(
|
| 36 |
-
#gr.Markdown("# <center> Alyxsissy TTS Preview </center>")
|
| 37 |
-
#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>")
|
| 38 |
-
with gr.Row(variant='panel'):
|
| 39 |
-
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key')
|
| 40 |
-
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1-hd')
|
| 41 |
-
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice', value='nova')
|
| 42 |
-
|
| 43 |
-
text = gr.Textbox(label="Input Text", placeholder="Enter your text and then click on the button below.")
|
| 44 |
-
btn = gr.Button("Run", variant="primary")
|
| 45 |
-
output_audio = gr.Audio(label="Speech Output")
|
| 46 |
-
|
| 47 |
-
text.submit(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
|
| 48 |
-
btn.click(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
|
| 49 |
-
|
| 50 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
+
import time
|
| 5 |
+
from openai import OpenAI
|
| 6 |
+
|
| 7 |
+
def tts(text, model, voice, api_key):
|
| 8 |
+
if api_key == '':
|
| 9 |
+
raise gr.Error('Please enter your OpenAI API Key')
|
| 10 |
+
else:
|
| 11 |
+
try:
|
| 12 |
+
client = OpenAI(api_key=api_key)
|
| 13 |
+
|
| 14 |
+
response = client.audio.speech.create(
|
| 15 |
+
model=model, # "tts-1","tts-1-hd"
|
| 16 |
+
voice=voice, # 'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
|
| 17 |
+
input=text,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
except Exception as error:
|
| 21 |
+
# Handle any exception that occurs
|
| 22 |
+
print(str(error))
|
| 23 |
+
raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
|
| 24 |
+
|
| 25 |
+
# Create a temp file to save the audio
|
| 26 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
| 27 |
+
temp_file.write(response.content)
|
| 28 |
+
|
| 29 |
+
# Get the file path of the temp file
|
| 30 |
+
temp_file_path = temp_file.name
|
| 31 |
+
|
| 32 |
+
return temp_file_path
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
#gr.Markdown("# <center> Alyxsissy TTS Preview </center>")
|
| 37 |
+
#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>")
|
| 38 |
+
with gr.Row(variant='panel'):
|
| 39 |
+
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key')
|
| 40 |
+
model = gr.Dropdown(choices=['tts-1','tts-1-hd','gpt-4o-mini-tts'], label='Model', value='tts-1-hd')
|
| 41 |
+
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice', value='nova')
|
| 42 |
+
|
| 43 |
+
text = gr.Textbox(label="Input Text", placeholder="Enter your text and then click on the button below.")
|
| 44 |
+
btn = gr.Button("Run", variant="primary")
|
| 45 |
+
output_audio = gr.Audio(label="Speech Output")
|
| 46 |
+
|
| 47 |
+
text.submit(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
|
| 48 |
+
btn.click(fn=tts, inputs=[text, model, voice, api_key], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
|
| 49 |
+
|
| 50 |
+
demo.launch(theme='Nymbo/Alyx_Theme')
|
requirements.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
openai
|
|
|
|
| 1 |
+
openai>=1.40
|