dongsiqie commited on
Commit
9885248
·
1 Parent(s): d90ebbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -5,15 +5,19 @@ from openai import OpenAI
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"
@@ -45,13 +49,14 @@ with gr.Blocks() as demo:
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()
 
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,url):
15
  if api_key == '':
16
  raise gr.Error('Please enter your OpenAI API Key')
17
  else:
18
  try:
19
+ headers = create_header(api_key)
20
+ url = url
 
21
  input_text = text
22
  query = {
23
  "model":model,# "tts-1","tts-1-hd"
 
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='alloy')
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,url], outputs=output_audio, api_name="tts_enter_key", concurrency_limit=None)
60
+ btn.click(fn=tts, inputs=[text, model, voice, api_key,url], outputs=output_audio, api_name="tts_button", concurrency_limit=None)
61
 
62
  demo.launch()