Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -4,12 +4,14 @@ import tempfile
4
  from openai import OpenAI
5
 
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"
@@ -36,6 +38,7 @@ with gr.Blocks() as demo:
36
  gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </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 to access the TTS demo')
40
  model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
41
  voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='alloy')
@@ -44,7 +47,7 @@ with gr.Blocks() as demo:
44
  btn = gr.Button("Text-To-Speech")
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()
 
4
  from openai import OpenAI
5
 
6
 
7
+ def tts(text, model, voice, api_key, api_base):
8
  if api_key == '':
9
  raise gr.Error('Please enter your OpenAI API Key')
10
+ if api_base == '':
11
+ api_base = "https://api.openai.com/v1"
12
  else:
13
  try:
14
+ client = OpenAI(api_key=api_key, api_base=api_base)
15
 
16
  response = client.audio.speech.create(
17
  model=model, # "tts-1","tts-1-hd"
 
38
  gr.Markdown("# <center> OpenAI Text-To-Speech API with Gradio </center>")
39
  #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>")
40
  with gr.Row(variant='panel'):
41
+ api_base = gr.Textbox(type='text', label='OpenAI base URL', placeholder='Enter your base URL to access the TTS demo')
42
  api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='Enter your API key to access the TTS demo')
43
  model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='Model', value='tts-1')
44
  voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='Voice Options', value='alloy')
 
47
  btn = gr.Button("Text-To-Speech")
48
  output_audio = gr.Audio(label="Speech Output")
49
 
50
+ text.submit(fn=tts, inputs=[text, model, voice, api_key, api_base], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
51
+ btn.click(fn=tts, inputs=[text, model, voice, api_key, api_base], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
52
 
53
  demo.launch()