7
7
import importlib
8
8
9
9
# Add the project root directory to the Python path
10
- sys .path .insert (0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )))
10
+ sys .path .insert (0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." )))
11
11
12
12
from tts_webui .css .css import full_css
13
13
@@ -321,23 +321,27 @@ def display_extension_ui(x, is_installed, is_disabled):
321
321
# Check if this is a built-in extension
322
322
is_builtin = package_name .startswith ("extensions.builtin" )
323
323
324
+ def install_extension ():
325
+ yield from pip_install_wrapper (x ["requirements" ], package_name )()
326
+
324
327
if is_installed :
325
328
if not is_builtin :
326
329
# Update button (only for non-builtin extensions)
327
330
update_btn = gr .Button ("Update" , variant = "primary" )
328
331
update_btn .click (
329
- fn = lambda pkg = package_name , req = x [
330
- "requirements"
331
- ]: pip_install_wrapper (req , pkg )(),
332
+ fn = install_extension ,
332
333
outputs = [gr .HTML ()],
333
334
)
334
335
336
+ def uninstall_extension ():
337
+ yield from pip_uninstall_wrapper (
338
+ package_name , package_name
339
+ )()
340
+
335
341
# Uninstall button (only for non-builtin extensions)
336
342
uninstall_btn = gr .Button ("Uninstall" , variant = "stop" )
337
343
uninstall_btn .click (
338
- fn = lambda pkg = package_name : pip_uninstall_wrapper (
339
- pkg , pkg
340
- )(),
344
+ fn = uninstall_extension ,
341
345
outputs = [gr .HTML ()],
342
346
)
343
347
@@ -361,6 +365,12 @@ def toggle_extension(package_name=package_name):
361
365
toggle_btn .click (
362
366
fn = toggle_extension ,
363
367
outputs = [gr .HTML ()],
368
+ ).then (
369
+ fn = lambda button_text : gr .Button (
370
+ "Enable" if button_text == "Disable" else "Disable"
371
+ ),
372
+ inputs = [toggle_btn ],
373
+ outputs = [toggle_btn ],
364
374
)
365
375
366
376
if is_builtin :
@@ -371,9 +381,7 @@ def toggle_extension(package_name=package_name):
371
381
# Install button
372
382
install_btn = gr .Button ("Install" , variant = "primary" )
373
383
install_btn .click (
374
- fn = lambda pkg = package_name , req = x [
375
- "requirements"
376
- ]: pip_install_wrapper (req , pkg )(),
384
+ fn = install_extension ,
377
385
outputs = [gr .HTML ()],
378
386
)
379
387
0 commit comments