Skip to content

Commit

Permalink
Show a list of extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmylo committed Jul 22, 2023
1 parent 96256cf commit d777473
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
18 changes: 18 additions & 0 deletions extensions/testextension/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import webui.extensionlib.callbacks as cb


def init_callback():
print('All extensions have initialized!')


cb.register_by_name('webui.init', init_callback)

cb.register_by_name('webui.settings', lambda: {
'test_setting': {
'tab': '🤖 Test extension',
'type': bool,
'default': False,
'readname': 'Test setting from test extension',
'description': 'This setting is loaded from the webui.settings event, It\'s actually part of a lambda expression'
}
})
1 change: 1 addition & 0 deletions extensions/testextension/scripts/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('This script was loaded through an extension.')
Empty file modified run.sh
100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions webui/extensionlib/extensionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def __init__(self, ext_name, load_states):
if os.path.isfile(extinfo):
with open(extinfo, 'r', encoding='utf8') as info_file:
self.info = json.load(info_file)
for k in ['name', 'description', 'author']:
if k not in self.info:
self.info[k] = 'Not provided'
if 'tags' not in self.info:
self.info['tags'] = []
else:
raise FileNotFoundError(f'No extension.json file for {ext_name} extension.')

Expand All @@ -62,6 +67,11 @@ def get_javascript(self) -> str | bool:
def set_enabled(self, new):
self.enabled = new
set_load_states()
try:
import gradio
return gradio.update(value=new)
except:
return new

def check_updates(self) -> UpdateStatus:
if not os.path.isdir(self.git_dir):
Expand Down
39 changes: 38 additions & 1 deletion webui/ui/tabs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,44 @@ def c(v):


def extensions_tab():
pass # TODO: figure out stuff to do here in order to effectively list components etc.
import webui.extensionlib.extensionmanager as em
with gradio.Tabs():
with gradio.Tab('✅ Installed'):
list_all_extensions()
with gradio.Tab('⬇️ Install new extensions'):
install_extensions_tab()


def list_all_extensions():
import webui.extensionlib.extensionmanager as em

with gradio.Row():
check_updates = gradio.Button('Check for updates', variant='primary')
update_seleted = gradio.Button('Update selected', variant='primary')
shutdown = gradio.Button('Shutdown audio webui')
shutdown.click(fn=lambda: os._exit(0))

with gradio.Row():
gradio.Markdown('## Name')
gradio.Markdown('## Description')
gradio.Markdown('## Author')
gradio.Markdown('## Update if available')
gradio.Markdown('## Enabled')

for e in em.states.values():
with gradio.Row() as parent:
gradio.Markdown(e.info['name'])
gradio.Markdown(e.info['description'])
gradio.Markdown(e.info['author'])
with gradio.Row():
updatemd = gradio.Markdown('Not checked')
updatecheck = gradio.Checkbox(False, label='Update', visible=False)
enabled = gradio.Checkbox(e.enabled, label='Enabled')
enabled.change(fn=e.set_enabled, inputs=enabled, outputs=enabled)


def install_extensions_tab():
pass


def extra_tab():
Expand Down

0 comments on commit d777473

Please sign in to comment.