Spaces:
Running
Running
matdmiller
commited on
Commit
·
e419f45
1
Parent(s):
d9a62b3
added cost calculation
Browse files
app.ipynb
CHANGED
@@ -237,6 +237,23 @@
|
|
237 |
" return len(input_text)"
|
238 |
]
|
239 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
{
|
241 |
"cell_type": "code",
|
242 |
"execution_count": null,
|
@@ -254,8 +271,11 @@
|
|
254 |
" tts_model_dropdown = gr.Dropdown(value='tts-1',choices=tts_models, label='Model')\n",
|
255 |
" tts_voice_dropdown = gr.Dropdown(value='alloy',choices=tts_voices,label='Voice')\n",
|
256 |
" input_text_length = gr.Label(label=\"Number of characters\")\n",
|
|
|
257 |
" output_audio = gr.Audio()\n",
|
258 |
" input_text.input(fn=get_input_text_len, inputs=input_text, outputs=input_text_length)\n",
|
|
|
|
|
259 |
" go_btn = gr.Button(\"Go\")\n",
|
260 |
" go_btn.click(fn=create_speech, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])\n",
|
261 |
" clear_btn = gr.Button('Clear')\n",
|
|
|
237 |
" return len(input_text)"
|
238 |
]
|
239 |
},
|
240 |
+
{
|
241 |
+
"cell_type": "code",
|
242 |
+
"execution_count": null,
|
243 |
+
"id": "0523a158-ee07-48b3-9350-ee39d4deee7f",
|
244 |
+
"metadata": {},
|
245 |
+
"outputs": [],
|
246 |
+
"source": [
|
247 |
+
"#| export\n",
|
248 |
+
"def get_generation_cost(input_text, tts_model_dropdown):\n",
|
249 |
+
" text_len = len(input_text)\n",
|
250 |
+
" if tts_model_dropdown.endswith('-hd'):\n",
|
251 |
+
" cost = text_len/1000 * 0.03\n",
|
252 |
+
" else:\n",
|
253 |
+
" cost = text_len/1000 * 0.015\n",
|
254 |
+
" return \"${:,.3f}\".format(cost)"
|
255 |
+
]
|
256 |
+
},
|
257 |
{
|
258 |
"cell_type": "code",
|
259 |
"execution_count": null,
|
|
|
271 |
" tts_model_dropdown = gr.Dropdown(value='tts-1',choices=tts_models, label='Model')\n",
|
272 |
" tts_voice_dropdown = gr.Dropdown(value='alloy',choices=tts_voices,label='Voice')\n",
|
273 |
" input_text_length = gr.Label(label=\"Number of characters\")\n",
|
274 |
+
" generation_cost = gr.Label(label=\"Generation cost\")\n",
|
275 |
" output_audio = gr.Audio()\n",
|
276 |
" input_text.input(fn=get_input_text_len, inputs=input_text, outputs=input_text_length)\n",
|
277 |
+
" input_text.input(fn=get_generation_cost, inputs=[input_text,tts_model_dropdown], outputs=generation_cost)\n",
|
278 |
+
" tts_model_dropdown.input(fn=get_generation_cost, inputs=[input_text,tts_model_dropdown], outputs=generation_cost)\n",
|
279 |
" go_btn = gr.Button(\"Go\")\n",
|
280 |
" go_btn.click(fn=create_speech, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])\n",
|
281 |
" clear_btn = gr.Button('Clear')\n",
|
app.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
# %% auto 0
|
4 |
__all__ = ['secret_import_failed', 'tts_voices', 'launch_kwargs', 'split_text', 'concatenate_mp3', 'create_speech',
|
5 |
-
'get_input_text_len']
|
6 |
|
7 |
# %% app.ipynb 1
|
8 |
#tts_openai_secrets.py content:
|
@@ -155,6 +155,15 @@ def get_input_text_len(input_text):
|
|
155 |
return len(input_text)
|
156 |
|
157 |
# %% app.ipynb 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
159 |
gr.Markdown("# OpenAI TTS")
|
160 |
gr.Markdown("Start typing below and then click **Go** to create the speech from your text. The current limit is 4,000 characters.")
|
@@ -164,19 +173,22 @@ with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
|
164 |
tts_model_dropdown = gr.Dropdown(value='tts-1',choices=tts_models, label='Model')
|
165 |
tts_voice_dropdown = gr.Dropdown(value='alloy',choices=tts_voices,label='Voice')
|
166 |
input_text_length = gr.Label(label="Number of characters")
|
|
|
167 |
output_audio = gr.Audio()
|
168 |
input_text.input(fn=get_input_text_len, inputs=input_text, outputs=input_text_length)
|
|
|
|
|
169 |
go_btn = gr.Button("Go")
|
170 |
go_btn.click(fn=create_speech, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])
|
171 |
clear_btn = gr.Button('Clear')
|
172 |
clear_btn.click(fn=lambda: '', outputs=input_text)
|
173 |
|
174 |
|
175 |
-
# %% app.ipynb
|
176 |
launch_kwargs = {'auth':('username',GRADIO_PASSWORD),
|
177 |
'auth_message':'Please log in to Mat\'s TTS App with username: username and password.'}
|
178 |
|
179 |
-
# %% app.ipynb
|
180 |
#.py launch
|
181 |
if __name__ == "__main__":
|
182 |
app.launch(**launch_kwargs)
|
|
|
2 |
|
3 |
# %% auto 0
|
4 |
__all__ = ['secret_import_failed', 'tts_voices', 'launch_kwargs', 'split_text', 'concatenate_mp3', 'create_speech',
|
5 |
+
'get_input_text_len', 'get_generation_cost']
|
6 |
|
7 |
# %% app.ipynb 1
|
8 |
#tts_openai_secrets.py content:
|
|
|
155 |
return len(input_text)
|
156 |
|
157 |
# %% app.ipynb 10
|
158 |
+
def get_generation_cost(input_text, tts_model_dropdown):
|
159 |
+
text_len = len(input_text)
|
160 |
+
if tts_model_dropdown.endswith('-hd'):
|
161 |
+
cost = text_len/1000 * 0.03
|
162 |
+
else:
|
163 |
+
cost = text_len/1000 * 0.015
|
164 |
+
return "${:,.3f}".format(cost)
|
165 |
+
|
166 |
+
# %% app.ipynb 11
|
167 |
with gr.Blocks(title='OpenAI TTS', head='OpenAI TTS') as app:
|
168 |
gr.Markdown("# OpenAI TTS")
|
169 |
gr.Markdown("Start typing below and then click **Go** to create the speech from your text. The current limit is 4,000 characters.")
|
|
|
173 |
tts_model_dropdown = gr.Dropdown(value='tts-1',choices=tts_models, label='Model')
|
174 |
tts_voice_dropdown = gr.Dropdown(value='alloy',choices=tts_voices,label='Voice')
|
175 |
input_text_length = gr.Label(label="Number of characters")
|
176 |
+
generation_cost = gr.Label(label="Generation cost")
|
177 |
output_audio = gr.Audio()
|
178 |
input_text.input(fn=get_input_text_len, inputs=input_text, outputs=input_text_length)
|
179 |
+
input_text.input(fn=get_generation_cost, inputs=[input_text,tts_model_dropdown], outputs=generation_cost)
|
180 |
+
tts_model_dropdown.input(fn=get_generation_cost, inputs=[input_text,tts_model_dropdown], outputs=generation_cost)
|
181 |
go_btn = gr.Button("Go")
|
182 |
go_btn.click(fn=create_speech, inputs=[input_text, tts_model_dropdown, tts_voice_dropdown], outputs=[output_audio])
|
183 |
clear_btn = gr.Button('Clear')
|
184 |
clear_btn.click(fn=lambda: '', outputs=input_text)
|
185 |
|
186 |
|
187 |
+
# %% app.ipynb 12
|
188 |
launch_kwargs = {'auth':('username',GRADIO_PASSWORD),
|
189 |
'auth_message':'Please log in to Mat\'s TTS App with username: username and password.'}
|
190 |
|
191 |
+
# %% app.ipynb 14
|
192 |
#.py launch
|
193 |
if __name__ == "__main__":
|
194 |
app.launch(**launch_kwargs)
|