Spaces:
Sleeping
Sleeping
Commit
•
72e0f08
1
Parent(s):
dc3a0c9
moved client connection into runner function
Browse files
app.ipynb
CHANGED
@@ -20,7 +20,8 @@
|
|
20 |
"name": "stdout",
|
21 |
"output_type": "stream",
|
22 |
"text": [
|
23 |
-
"OPENAI_API_KEY var not found. Trying import tts_openai_secrets\n"
|
|
|
24 |
]
|
25 |
}
|
26 |
],
|
@@ -78,14 +79,17 @@
|
|
78 |
"name": "stdout",
|
79 |
"output_type": "stream",
|
80 |
"text": [
|
81 |
-
"['tts-1-hd', 'tts-1-hd-1106', 'canary-tts', 'tts-1', 'tts-1-1106']\n"
|
82 |
]
|
83 |
}
|
84 |
],
|
85 |
"source": [
|
86 |
"#| export\n",
|
87 |
-
"
|
88 |
-
"
|
|
|
|
|
|
|
89 |
]
|
90 |
},
|
91 |
{
|
@@ -99,17 +103,6 @@
|
|
99 |
"tts_voices = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']"
|
100 |
]
|
101 |
},
|
102 |
-
{
|
103 |
-
"cell_type": "code",
|
104 |
-
"execution_count": null,
|
105 |
-
"id": "c4e3957f-b97a-4aee-933d-44bfba60b633",
|
106 |
-
"metadata": {},
|
107 |
-
"outputs": [],
|
108 |
-
"source": [
|
109 |
-
"#| export\n",
|
110 |
-
"client = openai.OpenAI()"
|
111 |
-
]
|
112 |
-
},
|
113 |
{
|
114 |
"cell_type": "code",
|
115 |
"execution_count": null,
|
@@ -119,12 +112,14 @@
|
|
119 |
"source": [
|
120 |
"#| export\n",
|
121 |
"def create_speech(input_text, model='tts-1', voice='alloy'):\n",
|
|
|
122 |
" response = client.audio.speech.create(\n",
|
123 |
" model=model,\n",
|
124 |
" voice=voice,\n",
|
125 |
" input=input_text,\n",
|
126 |
" speed=1.0\n",
|
127 |
" )\n",
|
|
|
128 |
" return response.content"
|
129 |
]
|
130 |
},
|
@@ -176,7 +171,7 @@
|
|
176 |
"name": "stdout",
|
177 |
"output_type": "stream",
|
178 |
"text": [
|
179 |
-
"Running on local URL: http://0.0.0.0:
|
180 |
"\n",
|
181 |
"To create a public link, set `share=True` in `launch()`.\n"
|
182 |
]
|
@@ -184,7 +179,7 @@
|
|
184 |
{
|
185 |
"data": {
|
186 |
"text/html": [
|
187 |
-
"<div><iframe src=\"http://localhost:
|
188 |
],
|
189 |
"text/plain": [
|
190 |
"<IPython.core.display.HTML object>"
|
@@ -217,7 +212,7 @@
|
|
217 |
"name": "stdout",
|
218 |
"output_type": "stream",
|
219 |
"text": [
|
220 |
-
"Closing server running on port:
|
221 |
]
|
222 |
}
|
223 |
],
|
|
|
20 |
"name": "stdout",
|
21 |
"output_type": "stream",
|
22 |
"text": [
|
23 |
+
"OPENAI_API_KEY var not found. Trying import tts_openai_secrets\n",
|
24 |
+
"import tts_openai_secrets succeeded\n"
|
25 |
]
|
26 |
}
|
27 |
],
|
|
|
79 |
"name": "stdout",
|
80 |
"output_type": "stream",
|
81 |
"text": [
|
82 |
+
"successfully got tts model list: ['tts-1-hd', 'tts-1-hd-1106', 'canary-tts', 'tts-1', 'tts-1-1106']\n"
|
83 |
]
|
84 |
}
|
85 |
],
|
86 |
"source": [
|
87 |
"#| export\n",
|
88 |
+
"try:\n",
|
89 |
+
" tts_models = [o.id for o in openai.models.list().data if 'tts' in o.id]\n",
|
90 |
+
" print('successfully got tts model list:', tts_models)\n",
|
91 |
+
"except:\n",
|
92 |
+
" tts_models = ['tts-1']"
|
93 |
]
|
94 |
},
|
95 |
{
|
|
|
103 |
"tts_voices = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']"
|
104 |
]
|
105 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
{
|
107 |
"cell_type": "code",
|
108 |
"execution_count": null,
|
|
|
112 |
"source": [
|
113 |
"#| export\n",
|
114 |
"def create_speech(input_text, model='tts-1', voice='alloy'):\n",
|
115 |
+
" client = openai.OpenAI()\n",
|
116 |
" response = client.audio.speech.create(\n",
|
117 |
" model=model,\n",
|
118 |
" voice=voice,\n",
|
119 |
" input=input_text,\n",
|
120 |
" speed=1.0\n",
|
121 |
" )\n",
|
122 |
+
" client.close()\n",
|
123 |
" return response.content"
|
124 |
]
|
125 |
},
|
|
|
171 |
"name": "stdout",
|
172 |
"output_type": "stream",
|
173 |
"text": [
|
174 |
+
"Running on local URL: http://0.0.0.0:7861\n",
|
175 |
"\n",
|
176 |
"To create a public link, set `share=True` in `launch()`.\n"
|
177 |
]
|
|
|
179 |
{
|
180 |
"data": {
|
181 |
"text/html": [
|
182 |
+
"<div><iframe src=\"http://localhost:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
183 |
],
|
184 |
"text/plain": [
|
185 |
"<IPython.core.display.HTML object>"
|
|
|
212 |
"name": "stdout",
|
213 |
"output_type": "stream",
|
214 |
"text": [
|
215 |
+
"Closing server running on port: 7861\n"
|
216 |
]
|
217 |
}
|
218 |
],
|
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['
|
5 |
|
6 |
# %% app.ipynb 1
|
7 |
#tts_openai_secrets.py content:
|
@@ -24,30 +24,32 @@ import gradio as gr
|
|
24 |
import openai
|
25 |
|
26 |
# %% app.ipynb 4
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
# %% app.ipynb 5
|
31 |
tts_voices = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']
|
32 |
|
33 |
# %% app.ipynb 6
|
34 |
-
client = openai.OpenAI()
|
35 |
-
|
36 |
-
# %% app.ipynb 7
|
37 |
def create_speech(input_text, model='tts-1', voice='alloy'):
|
|
|
38 |
response = client.audio.speech.create(
|
39 |
model=model,
|
40 |
voice=voice,
|
41 |
input=input_text,
|
42 |
speed=1.0
|
43 |
)
|
|
|
44 |
return response.content
|
45 |
|
46 |
-
# %% app.ipynb
|
47 |
def get_input_text_len(input_text):
|
48 |
return len(input_text)
|
49 |
|
50 |
-
# %% app.ipynb
|
51 |
with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
52 |
gr.Markdown("# OpenAI TTS")
|
53 |
gr.Markdown("Start typing below and then click **Go** to create the speech from your text. The current limit is 4,000 characters.")
|
@@ -65,5 +67,5 @@ with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
|
65 |
clear_btn.click(fn=lambda: '', outputs=input_text)
|
66 |
|
67 |
|
68 |
-
# %% app.ipynb
|
69 |
app.launch()
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['tts_voices', 'create_speech', 'get_input_text_len']
|
5 |
|
6 |
# %% app.ipynb 1
|
7 |
#tts_openai_secrets.py content:
|
|
|
24 |
import openai
|
25 |
|
26 |
# %% app.ipynb 4
|
27 |
+
try:
|
28 |
+
tts_models = [o.id for o in openai.models.list().data if 'tts' in o.id]
|
29 |
+
print('successfully got tts model list:', tts_models)
|
30 |
+
except:
|
31 |
+
tts_models = ['tts-1']
|
32 |
|
33 |
# %% app.ipynb 5
|
34 |
tts_voices = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']
|
35 |
|
36 |
# %% app.ipynb 6
|
|
|
|
|
|
|
37 |
def create_speech(input_text, model='tts-1', voice='alloy'):
|
38 |
+
client = openai.OpenAI()
|
39 |
response = client.audio.speech.create(
|
40 |
model=model,
|
41 |
voice=voice,
|
42 |
input=input_text,
|
43 |
speed=1.0
|
44 |
)
|
45 |
+
client.close()
|
46 |
return response.content
|
47 |
|
48 |
+
# %% app.ipynb 7
|
49 |
def get_input_text_len(input_text):
|
50 |
return len(input_text)
|
51 |
|
52 |
+
# %% app.ipynb 8
|
53 |
with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
54 |
gr.Markdown("# OpenAI TTS")
|
55 |
gr.Markdown("Start typing below and then click **Go** to create the speech from your text. The current limit is 4,000 characters.")
|
|
|
67 |
clear_btn.click(fn=lambda: '', outputs=input_text)
|
68 |
|
69 |
|
70 |
+
# %% app.ipynb 9
|
71 |
app.launch()
|