Spaces:
Sleeping
Sleeping
matdmiller
commited on
Commit
·
e0d016a
1
Parent(s):
fc37863
oauth-1
Browse files- .gitignore +1 -0
- app.ipynb +219 -27
- app.py +18 -5
.gitignore
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
tts_openai_secrets.py
|
2 |
tts_openai_secrets*
|
|
|
3 |
|
4 |
# Byte-compiled / optimized / DLL files
|
5 |
__pycache__/
|
|
|
1 |
tts_openai_secrets.py
|
2 |
tts_openai_secrets*
|
3 |
+
.virtual_documents
|
4 |
|
5 |
# Byte-compiled / optimized / DLL files
|
6 |
__pycache__/
|
app.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"id": "3bedf0dc-8d8e-4ede-a9e6-b8f35136aa00",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
@@ -12,10 +12,20 @@
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
-
"execution_count":
|
16 |
"id": "667802a7-0f36-4136-a381-e66210b20462",
|
17 |
"metadata": {},
|
18 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
"source": [
|
20 |
"#| export\n",
|
21 |
"#tts_openai_secrets.py content:\n",
|
@@ -44,7 +54,7 @@
|
|
44 |
},
|
45 |
{
|
46 |
"cell_type": "code",
|
47 |
-
"execution_count":
|
48 |
"id": "4d9863fc-969e-409b-8e20-b9c3cd2cc3e7",
|
49 |
"metadata": {},
|
50 |
"outputs": [],
|
@@ -58,7 +68,7 @@
|
|
58 |
},
|
59 |
{
|
60 |
"cell_type": "code",
|
61 |
-
"execution_count":
|
62 |
"id": "4f486d3a",
|
63 |
"metadata": {},
|
64 |
"outputs": [],
|
@@ -81,10 +91,18 @@
|
|
81 |
},
|
82 |
{
|
83 |
"cell_type": "code",
|
84 |
-
"execution_count":
|
85 |
"id": "0ffd33b4-cb9b-4c01-bff6-4c3102854ab6",
|
86 |
"metadata": {},
|
87 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
"source": [
|
89 |
"#| export\n",
|
90 |
"try:\n",
|
@@ -96,7 +114,7 @@
|
|
96 |
},
|
97 |
{
|
98 |
"cell_type": "code",
|
99 |
-
"execution_count":
|
100 |
"id": "2ddbca5d-4b04-43ab-afaf-430802980e78",
|
101 |
"metadata": {},
|
102 |
"outputs": [],
|
@@ -107,7 +125,7 @@
|
|
107 |
},
|
108 |
{
|
109 |
"cell_type": "code",
|
110 |
-
"execution_count":
|
111 |
"id": "8eb7e7d5-7121-4762-b8d1-e5a9539e2b36",
|
112 |
"metadata": {},
|
113 |
"outputs": [],
|
@@ -118,7 +136,7 @@
|
|
118 |
},
|
119 |
{
|
120 |
"cell_type": "code",
|
121 |
-
"execution_count":
|
122 |
"id": "52d373be-3a79-412e-8ca2-92bb443fa52d",
|
123 |
"metadata": {},
|
124 |
"outputs": [],
|
@@ -130,7 +148,7 @@
|
|
130 |
},
|
131 |
{
|
132 |
"cell_type": "code",
|
133 |
-
"execution_count":
|
134 |
"id": "24674094-4d47-4e48-b591-55faabcff8df",
|
135 |
"metadata": {},
|
136 |
"outputs": [],
|
@@ -171,7 +189,7 @@
|
|
171 |
},
|
172 |
{
|
173 |
"cell_type": "code",
|
174 |
-
"execution_count":
|
175 |
"id": "e6224ae5-3792-42b2-8392-3abd42998a50",
|
176 |
"metadata": {},
|
177 |
"outputs": [],
|
@@ -209,7 +227,7 @@
|
|
209 |
},
|
210 |
{
|
211 |
"cell_type": "code",
|
212 |
-
"execution_count":
|
213 |
"id": "4691703d-ed0f-4481-8006-b2906289b780",
|
214 |
"metadata": {},
|
215 |
"outputs": [],
|
@@ -229,13 +247,14 @@
|
|
229 |
},
|
230 |
{
|
231 |
"cell_type": "code",
|
232 |
-
"execution_count":
|
233 |
"id": "e34bb4aa-698c-4452-8cda-bd02b38f7122",
|
234 |
"metadata": {},
|
235 |
"outputs": [],
|
236 |
"source": [
|
237 |
"#| export\n",
|
238 |
"def create_speech2(input_text, model='tts-1', voice='alloy', progress=gr.Progress(), **kwargs):\n",
|
|
|
239 |
" start = datetime.now()\n",
|
240 |
" # Split the input text into chunks\n",
|
241 |
" chunks = split_text(input_text)\n",
|
@@ -270,13 +289,14 @@
|
|
270 |
},
|
271 |
{
|
272 |
"cell_type": "code",
|
273 |
-
"execution_count":
|
274 |
"id": "5388e860",
|
275 |
"metadata": {},
|
276 |
"outputs": [],
|
277 |
"source": [
|
278 |
"#| export\n",
|
279 |
"def create_speech(input_text, model='tts-1', voice='alloy', progress=gr.Progress()):\n",
|
|
|
280 |
" # Split the input text into chunks\n",
|
281 |
" chunks = split_text(input_text)\n",
|
282 |
"\n",
|
@@ -320,7 +340,7 @@
|
|
320 |
},
|
321 |
{
|
322 |
"cell_type": "code",
|
323 |
-
"execution_count":
|
324 |
"id": "236dd8d3-4364-4731-af93-7dcdec6f18a1",
|
325 |
"metadata": {},
|
326 |
"outputs": [],
|
@@ -332,7 +352,7 @@
|
|
332 |
},
|
333 |
{
|
334 |
"cell_type": "code",
|
335 |
-
"execution_count":
|
336 |
"id": "0523a158-ee07-48b3-9350-ee39d4deee7f",
|
337 |
"metadata": {},
|
338 |
"outputs": [],
|
@@ -349,10 +369,33 @@
|
|
349 |
},
|
350 |
{
|
351 |
"cell_type": "code",
|
352 |
-
"execution_count":
|
353 |
-
"id": "
|
354 |
"metadata": {},
|
355 |
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
"source": [
|
357 |
"#| export\n",
|
358 |
"with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:\n",
|
@@ -374,28 +417,165 @@
|
|
374 |
" go_btn.click(fn=create_speech2, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])\n",
|
375 |
" clear_btn = gr.Button('Clear')\n",
|
376 |
" clear_btn.click(fn=lambda: '', outputs=input_text)\n",
|
|
|
|
|
|
|
|
|
377 |
" "
|
378 |
]
|
379 |
},
|
380 |
{
|
381 |
"cell_type": "code",
|
382 |
-
"execution_count":
|
383 |
"id": "a00648a1-891b-470b-9959-f5d502055713",
|
384 |
"metadata": {},
|
385 |
"outputs": [],
|
386 |
"source": [
|
387 |
"#| export\n",
|
388 |
-
"launch_kwargs = {'auth':('username',GRADIO_PASSWORD),\n",
|
389 |
-
"
|
|
|
390 |
"queue_kwargs = {'default_concurrency_limit':10}"
|
391 |
]
|
392 |
},
|
393 |
{
|
394 |
"cell_type": "code",
|
395 |
-
"execution_count":
|
396 |
"id": "4b534fe7-4337-423e-846a-1bdb7cccc4ea",
|
397 |
"metadata": {},
|
398 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
"source": [
|
400 |
"#| hide\n",
|
401 |
"#Notebook launch\n",
|
@@ -430,7 +610,7 @@
|
|
430 |
},
|
431 |
{
|
432 |
"cell_type": "code",
|
433 |
-
"execution_count":
|
434 |
"id": "afbc9699-4d16-4060-88f4-cd1251754cbd",
|
435 |
"metadata": {},
|
436 |
"outputs": [],
|
@@ -461,9 +641,21 @@
|
|
461 |
],
|
462 |
"metadata": {
|
463 |
"kernelspec": {
|
464 |
-
"display_name": "
|
465 |
"language": "python",
|
466 |
-
"name": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
}
|
468 |
},
|
469 |
"nbformat": 4,
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"id": "3bedf0dc-8d8e-4ede-a9e6-b8f35136aa00",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
"id": "667802a7-0f36-4136-a381-e66210b20462",
|
17 |
"metadata": {},
|
18 |
+
"outputs": [
|
19 |
+
{
|
20 |
+
"name": "stdout",
|
21 |
+
"output_type": "stream",
|
22 |
+
"text": [
|
23 |
+
"OPENAI_API_KEY environment variable was not found.\n",
|
24 |
+
"GRADIO_PASSWORD environment variable was not found.\n",
|
25 |
+
"import tts_openai_secrets succeeded\n"
|
26 |
+
]
|
27 |
+
}
|
28 |
+
],
|
29 |
"source": [
|
30 |
"#| export\n",
|
31 |
"#tts_openai_secrets.py content:\n",
|
|
|
54 |
},
|
55 |
{
|
56 |
"cell_type": "code",
|
57 |
+
"execution_count": 3,
|
58 |
"id": "4d9863fc-969e-409b-8e20-b9c3cd2cc3e7",
|
59 |
"metadata": {},
|
60 |
"outputs": [],
|
|
|
68 |
},
|
69 |
{
|
70 |
"cell_type": "code",
|
71 |
+
"execution_count": 5,
|
72 |
"id": "4f486d3a",
|
73 |
"metadata": {},
|
74 |
"outputs": [],
|
|
|
91 |
},
|
92 |
{
|
93 |
"cell_type": "code",
|
94 |
+
"execution_count": 6,
|
95 |
"id": "0ffd33b4-cb9b-4c01-bff6-4c3102854ab6",
|
96 |
"metadata": {},
|
97 |
+
"outputs": [
|
98 |
+
{
|
99 |
+
"name": "stdout",
|
100 |
+
"output_type": "stream",
|
101 |
+
"text": [
|
102 |
+
"successfully got tts model list: ['tts-1-hd-1106', 'tts-1-hd', 'tts-1', 'tts-1-1106']\n"
|
103 |
+
]
|
104 |
+
}
|
105 |
+
],
|
106 |
"source": [
|
107 |
"#| export\n",
|
108 |
"try:\n",
|
|
|
114 |
},
|
115 |
{
|
116 |
"cell_type": "code",
|
117 |
+
"execution_count": 7,
|
118 |
"id": "2ddbca5d-4b04-43ab-afaf-430802980e78",
|
119 |
"metadata": {},
|
120 |
"outputs": [],
|
|
|
125 |
},
|
126 |
{
|
127 |
"cell_type": "code",
|
128 |
+
"execution_count": 8,
|
129 |
"id": "8eb7e7d5-7121-4762-b8d1-e5a9539e2b36",
|
130 |
"metadata": {},
|
131 |
"outputs": [],
|
|
|
136 |
},
|
137 |
{
|
138 |
"cell_type": "code",
|
139 |
+
"execution_count": 9,
|
140 |
"id": "52d373be-3a79-412e-8ca2-92bb443fa52d",
|
141 |
"metadata": {},
|
142 |
"outputs": [],
|
|
|
148 |
},
|
149 |
{
|
150 |
"cell_type": "code",
|
151 |
+
"execution_count": 10,
|
152 |
"id": "24674094-4d47-4e48-b591-55faabcff8df",
|
153 |
"metadata": {},
|
154 |
"outputs": [],
|
|
|
189 |
},
|
190 |
{
|
191 |
"cell_type": "code",
|
192 |
+
"execution_count": 11,
|
193 |
"id": "e6224ae5-3792-42b2-8392-3abd42998a50",
|
194 |
"metadata": {},
|
195 |
"outputs": [],
|
|
|
227 |
},
|
228 |
{
|
229 |
"cell_type": "code",
|
230 |
+
"execution_count": 12,
|
231 |
"id": "4691703d-ed0f-4481-8006-b2906289b780",
|
232 |
"metadata": {},
|
233 |
"outputs": [],
|
|
|
247 |
},
|
248 |
{
|
249 |
"cell_type": "code",
|
250 |
+
"execution_count": 13,
|
251 |
"id": "e34bb4aa-698c-4452-8cda-bd02b38f7122",
|
252 |
"metadata": {},
|
253 |
"outputs": [],
|
254 |
"source": [
|
255 |
"#| export\n",
|
256 |
"def create_speech2(input_text, model='tts-1', voice='alloy', progress=gr.Progress(), **kwargs):\n",
|
257 |
+
" assert authorized(None) is not None,'Unauthorized M'\n",
|
258 |
" start = datetime.now()\n",
|
259 |
" # Split the input text into chunks\n",
|
260 |
" chunks = split_text(input_text)\n",
|
|
|
289 |
},
|
290 |
{
|
291 |
"cell_type": "code",
|
292 |
+
"execution_count": 14,
|
293 |
"id": "5388e860",
|
294 |
"metadata": {},
|
295 |
"outputs": [],
|
296 |
"source": [
|
297 |
"#| export\n",
|
298 |
"def create_speech(input_text, model='tts-1', voice='alloy', progress=gr.Progress()):\n",
|
299 |
+
" assert authorized(None) is not None,'Unauthorized M'\n",
|
300 |
" # Split the input text into chunks\n",
|
301 |
" chunks = split_text(input_text)\n",
|
302 |
"\n",
|
|
|
340 |
},
|
341 |
{
|
342 |
"cell_type": "code",
|
343 |
+
"execution_count": 15,
|
344 |
"id": "236dd8d3-4364-4731-af93-7dcdec6f18a1",
|
345 |
"metadata": {},
|
346 |
"outputs": [],
|
|
|
352 |
},
|
353 |
{
|
354 |
"cell_type": "code",
|
355 |
+
"execution_count": 16,
|
356 |
"id": "0523a158-ee07-48b3-9350-ee39d4deee7f",
|
357 |
"metadata": {},
|
358 |
"outputs": [],
|
|
|
369 |
},
|
370 |
{
|
371 |
"cell_type": "code",
|
372 |
+
"execution_count": 17,
|
373 |
+
"id": "b5b29507-92bc-453d-bcc5-6402c17e9a0d",
|
374 |
"metadata": {},
|
375 |
"outputs": [],
|
376 |
+
"source": [
|
377 |
+
"#| export\n",
|
378 |
+
"def authorized(profile: gr.OAuthProfile) -> str:\n",
|
379 |
+
" if profile in [\"matdmiller\"]:\n",
|
380 |
+
" return f\"{profile.username}\"\n",
|
381 |
+
" return None"
|
382 |
+
]
|
383 |
+
},
|
384 |
+
{
|
385 |
+
"cell_type": "code",
|
386 |
+
"execution_count": 18,
|
387 |
+
"id": "e4fb3159-579b-4271-bc96-4cd1e2816eca",
|
388 |
+
"metadata": {},
|
389 |
+
"outputs": [
|
390 |
+
{
|
391 |
+
"name": "stderr",
|
392 |
+
"output_type": "stream",
|
393 |
+
"text": [
|
394 |
+
"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/oauth.py:138: UserWarning: Gradio does not support OAuth features outside of a Space environment. To help you debug your app locally, the login and logout buttons are mocked with your profile. To make it work, your machine must be logged in to Huggingface.\n",
|
395 |
+
" warnings.warn(\n"
|
396 |
+
]
|
397 |
+
}
|
398 |
+
],
|
399 |
"source": [
|
400 |
"#| export\n",
|
401 |
"with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:\n",
|
|
|
417 |
" go_btn.click(fn=create_speech2, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])\n",
|
418 |
" clear_btn = gr.Button('Clear')\n",
|
419 |
" clear_btn.click(fn=lambda: '', outputs=input_text)\n",
|
420 |
+
"\n",
|
421 |
+
" gr.LoginButton()\n",
|
422 |
+
" m = gr.Markdown('')\n",
|
423 |
+
" app.load(authorized, None, m)\n",
|
424 |
" "
|
425 |
]
|
426 |
},
|
427 |
{
|
428 |
"cell_type": "code",
|
429 |
+
"execution_count": 20,
|
430 |
"id": "a00648a1-891b-470b-9959-f5d502055713",
|
431 |
"metadata": {},
|
432 |
"outputs": [],
|
433 |
"source": [
|
434 |
"#| export\n",
|
435 |
+
"# launch_kwargs = {'auth':('username',GRADIO_PASSWORD),\n",
|
436 |
+
"# 'auth_message':'Please log in to Mat\\'s TTS App with username: username and password.'}\n",
|
437 |
+
"launch_kwargs = {}\n",
|
438 |
"queue_kwargs = {'default_concurrency_limit':10}"
|
439 |
]
|
440 |
},
|
441 |
{
|
442 |
"cell_type": "code",
|
443 |
+
"execution_count": 21,
|
444 |
"id": "4b534fe7-4337-423e-846a-1bdb7cccc4ea",
|
445 |
"metadata": {},
|
446 |
+
"outputs": [
|
447 |
+
{
|
448 |
+
"name": "stdout",
|
449 |
+
"output_type": "stream",
|
450 |
+
"text": [
|
451 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
452 |
+
"\n",
|
453 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
454 |
+
]
|
455 |
+
},
|
456 |
+
{
|
457 |
+
"data": {
|
458 |
+
"text/html": [
|
459 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
460 |
+
],
|
461 |
+
"text/plain": [
|
462 |
+
"<IPython.core.display.HTML object>"
|
463 |
+
]
|
464 |
+
},
|
465 |
+
"metadata": {},
|
466 |
+
"output_type": "display_data"
|
467 |
+
},
|
468 |
+
{
|
469 |
+
"data": {
|
470 |
+
"text/plain": []
|
471 |
+
},
|
472 |
+
"execution_count": 21,
|
473 |
+
"metadata": {},
|
474 |
+
"output_type": "execute_result"
|
475 |
+
},
|
476 |
+
{
|
477 |
+
"name": "stderr",
|
478 |
+
"output_type": "stream",
|
479 |
+
"text": [
|
480 |
+
"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/components/login_button.py:74: UserWarning: LoginButton created outside of a Blocks context. May not work unless you call its `activate()` method manually.\n",
|
481 |
+
" warnings.warn(\n",
|
482 |
+
"Traceback (most recent call last):\n",
|
483 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/queueing.py\", line 532, in process_events\n",
|
484 |
+
" response = await route_utils.call_process_api(\n",
|
485 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
486 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/route_utils.py\", line 276, in call_process_api\n",
|
487 |
+
" output = await app.get_blocks().process_api(\n",
|
488 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
489 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1928, in process_api\n",
|
490 |
+
" result = await self.call_function(\n",
|
491 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
492 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1500, in call_function\n",
|
493 |
+
" processed_input, progress_index, _ = special_args(\n",
|
494 |
+
" ^^^^^^^^^^^^^\n",
|
495 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/helpers.py\", line 907, in special_args\n",
|
496 |
+
" raise Error(\n",
|
497 |
+
"gradio.exceptions.Error: 'This action requires a logged in user. Please sign in and retry.'\n",
|
498 |
+
"Traceback (most recent call last):\n",
|
499 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/queueing.py\", line 532, in process_events\n",
|
500 |
+
" response = await route_utils.call_process_api(\n",
|
501 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
502 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/route_utils.py\", line 276, in call_process_api\n",
|
503 |
+
" output = await app.get_blocks().process_api(\n",
|
504 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
505 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1928, in process_api\n",
|
506 |
+
" result = await self.call_function(\n",
|
507 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
508 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1500, in call_function\n",
|
509 |
+
" processed_input, progress_index, _ = special_args(\n",
|
510 |
+
" ^^^^^^^^^^^^^\n",
|
511 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/helpers.py\", line 907, in special_args\n",
|
512 |
+
" raise Error(\n",
|
513 |
+
"gradio.exceptions.Error: 'This action requires a logged in user. Please sign in and retry.'\n",
|
514 |
+
"Traceback (most recent call last):\n",
|
515 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/queueing.py\", line 532, in process_events\n",
|
516 |
+
" response = await route_utils.call_process_api(\n",
|
517 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
518 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/route_utils.py\", line 276, in call_process_api\n",
|
519 |
+
" output = await app.get_blocks().process_api(\n",
|
520 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
521 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1928, in process_api\n",
|
522 |
+
" result = await self.call_function(\n",
|
523 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
524 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1500, in call_function\n",
|
525 |
+
" processed_input, progress_index, _ = special_args(\n",
|
526 |
+
" ^^^^^^^^^^^^^\n",
|
527 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/helpers.py\", line 907, in special_args\n",
|
528 |
+
" raise Error(\n",
|
529 |
+
"gradio.exceptions.Error: 'This action requires a logged in user. Please sign in and retry.'\n"
|
530 |
+
]
|
531 |
+
},
|
532 |
+
{
|
533 |
+
"name": "stdout",
|
534 |
+
"output_type": "stream",
|
535 |
+
"text": [
|
536 |
+
"Processing time: 0 seconds.\n",
|
537 |
+
"Processing time: 0 seconds.\n"
|
538 |
+
]
|
539 |
+
},
|
540 |
+
{
|
541 |
+
"name": "stderr",
|
542 |
+
"output_type": "stream",
|
543 |
+
"text": [
|
544 |
+
"Traceback (most recent call last):\n",
|
545 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/queueing.py\", line 532, in process_events\n",
|
546 |
+
" response = await route_utils.call_process_api(\n",
|
547 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
548 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/route_utils.py\", line 276, in call_process_api\n",
|
549 |
+
" output = await app.get_blocks().process_api(\n",
|
550 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
551 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1928, in process_api\n",
|
552 |
+
" result = await self.call_function(\n",
|
553 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
554 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1500, in call_function\n",
|
555 |
+
" processed_input, progress_index, _ = special_args(\n",
|
556 |
+
" ^^^^^^^^^^^^^\n",
|
557 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/helpers.py\", line 907, in special_args\n",
|
558 |
+
" raise Error(\n",
|
559 |
+
"gradio.exceptions.Error: 'This action requires a logged in user. Please sign in and retry.'\n",
|
560 |
+
"Traceback (most recent call last):\n",
|
561 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/queueing.py\", line 532, in process_events\n",
|
562 |
+
" response = await route_utils.call_process_api(\n",
|
563 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
564 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/route_utils.py\", line 276, in call_process_api\n",
|
565 |
+
" output = await app.get_blocks().process_api(\n",
|
566 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
567 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1928, in process_api\n",
|
568 |
+
" result = await self.call_function(\n",
|
569 |
+
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
570 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/blocks.py\", line 1500, in call_function\n",
|
571 |
+
" processed_input, progress_index, _ = special_args(\n",
|
572 |
+
" ^^^^^^^^^^^^^\n",
|
573 |
+
" File \"/Users/mathewmiller/anaconda3/envs/gradio1/lib/python3.11/site-packages/gradio/helpers.py\", line 907, in special_args\n",
|
574 |
+
" raise Error(\n",
|
575 |
+
"gradio.exceptions.Error: 'This action requires a logged in user. Please sign in and retry.'\n"
|
576 |
+
]
|
577 |
+
}
|
578 |
+
],
|
579 |
"source": [
|
580 |
"#| hide\n",
|
581 |
"#Notebook launch\n",
|
|
|
610 |
},
|
611 |
{
|
612 |
"cell_type": "code",
|
613 |
+
"execution_count": 22,
|
614 |
"id": "afbc9699-4d16-4060-88f4-cd1251754cbd",
|
615 |
"metadata": {},
|
616 |
"outputs": [],
|
|
|
641 |
],
|
642 |
"metadata": {
|
643 |
"kernelspec": {
|
644 |
+
"display_name": "gradio1",
|
645 |
"language": "python",
|
646 |
+
"name": "gradio1"
|
647 |
+
},
|
648 |
+
"language_info": {
|
649 |
+
"codemirror_mode": {
|
650 |
+
"name": "ipython",
|
651 |
+
"version": 3
|
652 |
+
},
|
653 |
+
"file_extension": ".py",
|
654 |
+
"mimetype": "text/x-python",
|
655 |
+
"name": "python",
|
656 |
+
"nbconvert_exporter": "python",
|
657 |
+
"pygments_lexer": "ipython3",
|
658 |
+
"version": "3.11.8"
|
659 |
}
|
660 |
},
|
661 |
"nbformat": 4,
|
app.py
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
# %% auto 0
|
4 |
__all__ = ['secret_import_failed', 'tts_voices', 'clean_text_prompt', 'OPENAI_CLIENT_TTS_THREADS', 'launch_kwargs',
|
5 |
'queue_kwargs', 'split_text', 'concatenate_mp3', 'create_speech_openai', 'create_speech2', 'create_speech',
|
6 |
-
'get_input_text_len', 'get_generation_cost']
|
7 |
|
8 |
# %% app.ipynb 1
|
9 |
#tts_openai_secrets.py content:
|
@@ -139,6 +139,7 @@ def create_speech_openai(chunk_idx, input, model='tts-1', voice='alloy', speed=1
|
|
139 |
|
140 |
# %% app.ipynb 11
|
141 |
def create_speech2(input_text, model='tts-1', voice='alloy', progress=gr.Progress(), **kwargs):
|
|
|
142 |
start = datetime.now()
|
143 |
# Split the input text into chunks
|
144 |
chunks = split_text(input_text)
|
@@ -173,6 +174,7 @@ def create_speech2(input_text, model='tts-1', voice='alloy', progress=gr.Progres
|
|
173 |
|
174 |
# %% app.ipynb 12
|
175 |
def create_speech(input_text, model='tts-1', voice='alloy', progress=gr.Progress()):
|
|
|
176 |
# Split the input text into chunks
|
177 |
chunks = split_text(input_text)
|
178 |
|
@@ -228,6 +230,12 @@ def get_generation_cost(input_text, tts_model_dropdown):
|
|
228 |
return "${:,.3f}".format(cost)
|
229 |
|
230 |
# %% app.ipynb 15
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
232 |
gr.Markdown("# OpenAI TTS")
|
233 |
gr.Markdown("""Start typing below and then click **Go** to create the speech from your text. The current limit is 4,000 characters.
|
@@ -247,14 +255,19 @@ For requests longer than 4,000 chars they will be broken into chunks of 4,000 or
|
|
247 |
go_btn.click(fn=create_speech2, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])
|
248 |
clear_btn = gr.Button('Clear')
|
249 |
clear_btn.click(fn=lambda: '', outputs=input_text)
|
|
|
|
|
|
|
|
|
250 |
|
251 |
|
252 |
-
# %% app.ipynb
|
253 |
-
launch_kwargs = {'auth':('username',GRADIO_PASSWORD),
|
254 |
-
|
|
|
255 |
queue_kwargs = {'default_concurrency_limit':10}
|
256 |
|
257 |
-
# %% app.ipynb
|
258 |
#.py launch
|
259 |
if __name__ == "__main__":
|
260 |
app.queue(**queue_kwargs)
|
|
|
3 |
# %% auto 0
|
4 |
__all__ = ['secret_import_failed', 'tts_voices', 'clean_text_prompt', 'OPENAI_CLIENT_TTS_THREADS', 'launch_kwargs',
|
5 |
'queue_kwargs', 'split_text', 'concatenate_mp3', 'create_speech_openai', 'create_speech2', 'create_speech',
|
6 |
+
'get_input_text_len', 'get_generation_cost', 'authorized']
|
7 |
|
8 |
# %% app.ipynb 1
|
9 |
#tts_openai_secrets.py content:
|
|
|
139 |
|
140 |
# %% app.ipynb 11
|
141 |
def create_speech2(input_text, model='tts-1', voice='alloy', progress=gr.Progress(), **kwargs):
|
142 |
+
assert authorized(None) is not None,'Unauthorized M'
|
143 |
start = datetime.now()
|
144 |
# Split the input text into chunks
|
145 |
chunks = split_text(input_text)
|
|
|
174 |
|
175 |
# %% app.ipynb 12
|
176 |
def create_speech(input_text, model='tts-1', voice='alloy', progress=gr.Progress()):
|
177 |
+
assert authorized(None) is not None,'Unauthorized M'
|
178 |
# Split the input text into chunks
|
179 |
chunks = split_text(input_text)
|
180 |
|
|
|
230 |
return "${:,.3f}".format(cost)
|
231 |
|
232 |
# %% app.ipynb 15
|
233 |
+
def authorized(profile: gr.OAuthProfile) -> str:
|
234 |
+
if profile in ["matdmiller"]:
|
235 |
+
return f"{profile.username}"
|
236 |
+
return None
|
237 |
+
|
238 |
+
# %% app.ipynb 16
|
239 |
with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
240 |
gr.Markdown("# OpenAI TTS")
|
241 |
gr.Markdown("""Start typing below and then click **Go** to create the speech from your text. The current limit is 4,000 characters.
|
|
|
255 |
go_btn.click(fn=create_speech2, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])
|
256 |
clear_btn = gr.Button('Clear')
|
257 |
clear_btn.click(fn=lambda: '', outputs=input_text)
|
258 |
+
|
259 |
+
gr.LoginButton()
|
260 |
+
m = gr.Markdown('')
|
261 |
+
app.load(authorized, None, m)
|
262 |
|
263 |
|
264 |
+
# %% app.ipynb 17
|
265 |
+
# launch_kwargs = {'auth':('username',GRADIO_PASSWORD),
|
266 |
+
# 'auth_message':'Please log in to Mat\'s TTS App with username: username and password.'}
|
267 |
+
launch_kwargs = {}
|
268 |
queue_kwargs = {'default_concurrency_limit':10}
|
269 |
|
270 |
+
# %% app.ipynb 19
|
271 |
#.py launch
|
272 |
if __name__ == "__main__":
|
273 |
app.queue(**queue_kwargs)
|