Spaces:
Sleeping
Sleeping
working small from main
Browse files- .gradio/certificate.pem +31 -0
- app_starter_gui/css.py +14 -6
- app_starter_gui/gradio_app.py +22 -8
- buttons.yaml +1 -1
- gradio_app.py +51 -0
- nbs/01_css.ipynb +49 -13
- nbs/02_gradio_app.ipynb +57 -15
- test.ipynb +158 -0
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
| 10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
| 11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
| 12 |
+
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
|
| 13 |
+
B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
|
| 14 |
+
KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn
|
| 15 |
+
OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn
|
| 16 |
+
jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw
|
| 17 |
+
qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI
|
| 18 |
+
rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
|
| 19 |
+
HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
|
| 20 |
+
hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
|
| 21 |
+
ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
|
| 22 |
+
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
|
| 23 |
+
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
| 24 |
+
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
| 25 |
+
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
app_starter_gui/css.py
CHANGED
|
@@ -4,6 +4,8 @@
|
|
| 4 |
__all__ = ['generate_css', 'test_generate_css']
|
| 5 |
|
| 6 |
# %% ../nbs/01_css.ipynb 2
|
|
|
|
|
|
|
| 7 |
from .core import Button
|
| 8 |
from fastcore.test import * # for test_assert
|
| 9 |
|
|
@@ -72,10 +74,16 @@ def generate_css(buttons):
|
|
| 72 |
"""
|
| 73 |
|
| 74 |
all_css = []
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
return "\n".join(all_css)
|
| 81 |
|
|
@@ -89,7 +97,7 @@ def test_generate_css():
|
|
| 89 |
Button("Search", "img.jpg", "https://search.com", "Search")
|
| 90 |
]
|
| 91 |
css = generate_css(buttons)
|
| 92 |
-
test('#
|
| 93 |
-
test('#
|
| 94 |
|
| 95 |
test_generate_css()
|
|
|
|
| 4 |
__all__ = ['generate_css', 'test_generate_css']
|
| 5 |
|
| 6 |
# %% ../nbs/01_css.ipynb 2
|
| 7 |
+
from operator import attrgetter
|
| 8 |
+
from itertools import groupby
|
| 9 |
from .core import Button
|
| 10 |
from fastcore.test import * # for test_assert
|
| 11 |
|
|
|
|
| 74 |
"""
|
| 75 |
|
| 76 |
all_css = []
|
| 77 |
+
|
| 78 |
+
# Sort buttons by app_type to match the dashboard layout
|
| 79 |
+
buttons = sorted(buttons, key=attrgetter('app_type'))
|
| 80 |
+
button_groups = {k: list(g) for k, g in groupby(buttons, key=attrgetter('app_type'))}
|
| 81 |
+
|
| 82 |
+
for app_type, type_buttons in button_groups.items():
|
| 83 |
+
for button_idx, button in enumerate(type_buttons, 1):
|
| 84 |
+
btn_id = f"btn_{app_type}_{button_idx}"
|
| 85 |
+
css = css_template.format(btn_id=btn_id, image_url=button.image_url)
|
| 86 |
+
all_css.append(css)
|
| 87 |
|
| 88 |
return "\n".join(all_css)
|
| 89 |
|
|
|
|
| 97 |
Button("Search", "img.jpg", "https://search.com", "Search")
|
| 98 |
]
|
| 99 |
css = generate_css(buttons)
|
| 100 |
+
test('#btn_ai_1', css.lower(), lambda x,y: x in y)
|
| 101 |
+
test('#btn_search_1', css.lower(), lambda x,y: x in y)
|
| 102 |
|
| 103 |
test_generate_css()
|
app_starter_gui/gradio_app.py
CHANGED
|
@@ -5,6 +5,8 @@ __all__ = ['create_app', 'test_create_app']
|
|
| 5 |
|
| 6 |
# %% ../nbs/02_gradio_app.ipynb 2
|
| 7 |
import gradio as gr
|
|
|
|
|
|
|
| 8 |
from .core import Button, load_buttons
|
| 9 |
from .css import generate_css
|
| 10 |
|
|
@@ -20,16 +22,28 @@ def create_app(yaml_file='buttons.yaml', css_generator=generate_css):
|
|
| 20 |
"""
|
| 21 |
buttons = load_buttons(yaml_file)
|
| 22 |
css = generate_css(buttons)
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
with gr.Blocks(css=css) as blocks:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
return blocks
|
| 34 |
|
| 35 |
# %% ../nbs/02_gradio_app.ipynb 6
|
|
|
|
| 5 |
|
| 6 |
# %% ../nbs/02_gradio_app.ipynb 2
|
| 7 |
import gradio as gr
|
| 8 |
+
from itertools import groupby
|
| 9 |
+
from operator import attrgetter
|
| 10 |
from .core import Button, load_buttons
|
| 11 |
from .css import generate_css
|
| 12 |
|
|
|
|
| 22 |
"""
|
| 23 |
buttons = load_buttons(yaml_file)
|
| 24 |
css = generate_css(buttons)
|
| 25 |
+
|
| 26 |
+
buttons_sorted = sorted(buttons, key=attrgetter('app_type'))
|
| 27 |
+
button_groups = {k: list(g) for k, g in groupby(buttons_sorted, key=attrgetter('app_type'))}
|
| 28 |
|
| 29 |
with gr.Blocks(css=css) as blocks:
|
| 30 |
+
with gr.Row():
|
| 31 |
+
# Create a column for each app_type
|
| 32 |
+
for app_type, type_buttons in button_groups.items():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
gr.Markdown(f"### {app_type}")
|
| 35 |
+
for button_idx, button in enumerate(type_buttons):
|
| 36 |
+
btn = gr.Button(
|
| 37 |
+
value=button.label,
|
| 38 |
+
elem_id=f"btn_{app_type}_{button_idx}", # Make unique ID for each button
|
| 39 |
+
scale=1,
|
| 40 |
+
)
|
| 41 |
+
btn.click(
|
| 42 |
+
fn=None,
|
| 43 |
+
inputs=None,
|
| 44 |
+
outputs=None,
|
| 45 |
+
js=f"() => {{ window.open('{button.link_url}', '_blank'); }}"
|
| 46 |
+
)
|
| 47 |
return blocks
|
| 48 |
|
| 49 |
# %% ../nbs/02_gradio_app.ipynb 6
|
buttons.yaml
CHANGED
|
@@ -3,6 +3,6 @@
|
|
| 3 |
link_url: https://huggingface.co/spaces/Hopsakee/fabric_to_espanso
|
| 4 |
app_type: Prompt
|
| 5 |
- label: Jaws of the Lion
|
| 6 |
-
image_url:
|
| 7 |
link_url: https://notebooklm.google.com/notebook/ac6595f8-963c-4bd8-87cf-26b7007434a6?_gl=1*10y09ch*_ga*OTQ0NDQwODcwLjE3MzUzNzU4MDc.*_ga_W0LDH41ZCB*MTczNjk3MjM5NS43LjAuMTczNjk3MjM5NS4wLjAuMA..
|
| 8 |
app_type: Bordspel
|
|
|
|
| 3 |
link_url: https://huggingface.co/spaces/Hopsakee/fabric_to_espanso
|
| 4 |
app_type: Prompt
|
| 5 |
- label: Jaws of the Lion
|
| 6 |
+
image_url: https://static1.srcdn.com/wordpress/wp-content/uploads/2020/06/Gloomhaven-Jaws-of-the-Lion-Hatchet.jpg
|
| 7 |
link_url: https://notebooklm.google.com/notebook/ac6595f8-963c-4bd8-87cf-26b7007434a6?_gl=1*10y09ch*_ga*OTQ0NDQwODcwLjE3MzUzNzU4MDc.*_ga_W0LDH41ZCB*MTczNjk3MjM5NS43LjAuMTczNjk3MjM5NS4wLjAuMA..
|
| 8 |
app_type: Bordspel
|
gradio_app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_gradio_app.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['create_app', 'test_create_app']
|
| 5 |
+
|
| 6 |
+
# %% ../nbs/02_gradio_app.ipynb 2
|
| 7 |
+
import gradio as gr
|
| 8 |
+
from itertools import groupby
|
| 9 |
+
from operator import attrgetter
|
| 10 |
+
from app_starter_gui.core import Button, load_buttons
|
| 11 |
+
from app_starter_gui.css import generate_css
|
| 12 |
+
|
| 13 |
+
# %% ../nbs/02_gradio_app.ipynb 4
|
| 14 |
+
def create_app(yaml_file='buttons.yaml', css_generator=generate_css):
|
| 15 |
+
"""Create a Gradio dashboard for the button interface
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
yaml_file: Path to YAML file containing button data (default: 'buttons.yaml')
|
| 19 |
+
css_generator: Function to generate CSS (default: generate_css)
|
| 20 |
+
Returns:
|
| 21 |
+
gr.Blocks: Gradio interface
|
| 22 |
+
"""
|
| 23 |
+
buttons = load_buttons(yaml_file)
|
| 24 |
+
css = generate_css(buttons)
|
| 25 |
+
|
| 26 |
+
buttons_sorted = sorted(buttons, key=attrgetter('app_type'))
|
| 27 |
+
buttons_grouped = {k: list(g) for k, g in groupby(buttons_sorted, key=attrgetter('app_type'))}
|
| 28 |
+
|
| 29 |
+
with gr.Blocks(css=css) as blocks:
|
| 30 |
+
with gr.Row():
|
| 31 |
+
# Create a column for each app type
|
| 32 |
+
for app_type, type_buttons in buttons_grouped.items():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
gr.Markdown(f"### {app_type}")
|
| 35 |
+
for i, button in enumerate(type_buttons, 1):
|
| 36 |
+
btn = gr.Button(
|
| 37 |
+
value=button.label,
|
| 38 |
+
elem_id=f"btn_{app_type}_{i}",
|
| 39 |
+
scale=1,
|
| 40 |
+
)
|
| 41 |
+
btn.click(
|
| 42 |
+
fn=None,
|
| 43 |
+
inputs=None,
|
| 44 |
+
outputs=None,
|
| 45 |
+
js=f"() => {{ window.open('{button.link_url}', '_blank'); }}"
|
| 46 |
+
)
|
| 47 |
+
return blocks
|
| 48 |
+
|
| 49 |
+
if __name__ == '__main__':
|
| 50 |
+
demo = create_app()
|
| 51 |
+
demo.launch(share=True)
|
nbs/01_css.ipynb
CHANGED
|
@@ -16,7 +16,11 @@
|
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
"execution_count": null,
|
| 19 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"outputs": [],
|
| 21 |
"source": [
|
| 22 |
"#| default_exp css"
|
|
@@ -25,7 +29,11 @@
|
|
| 25 |
{
|
| 26 |
"cell_type": "code",
|
| 27 |
"execution_count": null,
|
| 28 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"outputs": [
|
| 30 |
{
|
| 31 |
"ename": "ModuleNotFoundError",
|
|
@@ -42,6 +50,8 @@
|
|
| 42 |
"source": [
|
| 43 |
"#| export\n",
|
| 44 |
"#| hide\n",
|
|
|
|
|
|
|
| 45 |
"from app_starter_gui.core import Button\n",
|
| 46 |
"from fastcore.test import * # for test_assert"
|
| 47 |
]
|
|
@@ -49,7 +59,11 @@
|
|
| 49 |
{
|
| 50 |
"cell_type": "code",
|
| 51 |
"execution_count": null,
|
| 52 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
"outputs": [],
|
| 54 |
"source": [
|
| 55 |
"from nbdev.showdoc import show_doc"
|
|
@@ -58,7 +72,11 @@
|
|
| 58 |
{
|
| 59 |
"cell_type": "code",
|
| 60 |
"execution_count": null,
|
| 61 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
"outputs": [],
|
| 63 |
"source": [
|
| 64 |
"#| export\n",
|
|
@@ -126,10 +144,16 @@
|
|
| 126 |
" \"\"\"\n",
|
| 127 |
" \n",
|
| 128 |
" all_css = []\n",
|
| 129 |
-
"
|
| 130 |
-
"
|
| 131 |
-
"
|
| 132 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
" \n",
|
| 134 |
" return \"\\n\".join(all_css)"
|
| 135 |
]
|
|
@@ -137,7 +161,11 @@
|
|
| 137 |
{
|
| 138 |
"cell_type": "code",
|
| 139 |
"execution_count": null,
|
| 140 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
"outputs": [
|
| 142 |
{
|
| 143 |
"ename": "NameError",
|
|
@@ -165,7 +193,11 @@
|
|
| 165 |
{
|
| 166 |
"cell_type": "code",
|
| 167 |
"execution_count": null,
|
| 168 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
"outputs": [
|
| 170 |
{
|
| 171 |
"ename": "NameError",
|
|
@@ -192,8 +224,8 @@
|
|
| 192 |
" Button(\"Search\", \"img.jpg\", \"https://search.com\", \"Search\")\n",
|
| 193 |
" ]\n",
|
| 194 |
" css = generate_css(buttons)\n",
|
| 195 |
-
" test('#
|
| 196 |
-
" test('#
|
| 197 |
"\n",
|
| 198 |
"test_generate_css()"
|
| 199 |
]
|
|
@@ -201,7 +233,11 @@
|
|
| 201 |
{
|
| 202 |
"cell_type": "code",
|
| 203 |
"execution_count": null,
|
| 204 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
"outputs": [],
|
| 206 |
"source": [
|
| 207 |
"#| hide\n",
|
|
|
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
"execution_count": null,
|
| 19 |
+
"metadata": {
|
| 20 |
+
"vscode": {
|
| 21 |
+
"languageId": "python"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
"outputs": [],
|
| 25 |
"source": [
|
| 26 |
"#| default_exp css"
|
|
|
|
| 29 |
{
|
| 30 |
"cell_type": "code",
|
| 31 |
"execution_count": null,
|
| 32 |
+
"metadata": {
|
| 33 |
+
"vscode": {
|
| 34 |
+
"languageId": "python"
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
"outputs": [
|
| 38 |
{
|
| 39 |
"ename": "ModuleNotFoundError",
|
|
|
|
| 50 |
"source": [
|
| 51 |
"#| export\n",
|
| 52 |
"#| hide\n",
|
| 53 |
+
"from operator import attrgetter\n",
|
| 54 |
+
"from itertools import groupby\n",
|
| 55 |
"from app_starter_gui.core import Button\n",
|
| 56 |
"from fastcore.test import * # for test_assert"
|
| 57 |
]
|
|
|
|
| 59 |
{
|
| 60 |
"cell_type": "code",
|
| 61 |
"execution_count": null,
|
| 62 |
+
"metadata": {
|
| 63 |
+
"vscode": {
|
| 64 |
+
"languageId": "python"
|
| 65 |
+
}
|
| 66 |
+
},
|
| 67 |
"outputs": [],
|
| 68 |
"source": [
|
| 69 |
"from nbdev.showdoc import show_doc"
|
|
|
|
| 72 |
{
|
| 73 |
"cell_type": "code",
|
| 74 |
"execution_count": null,
|
| 75 |
+
"metadata": {
|
| 76 |
+
"vscode": {
|
| 77 |
+
"languageId": "python"
|
| 78 |
+
}
|
| 79 |
+
},
|
| 80 |
"outputs": [],
|
| 81 |
"source": [
|
| 82 |
"#| export\n",
|
|
|
|
| 144 |
" \"\"\"\n",
|
| 145 |
" \n",
|
| 146 |
" all_css = []\n",
|
| 147 |
+
" \n",
|
| 148 |
+
" # Sort buttons by app_type to match the dashboard layout\n",
|
| 149 |
+
" buttons = sorted(buttons, key=attrgetter('app_type'))\n",
|
| 150 |
+
" button_groups = {k: list(g) for k, g in groupby(buttons, key=attrgetter('app_type'))}\n",
|
| 151 |
+
" \n",
|
| 152 |
+
" for app_type, type_buttons in button_groups.items():\n",
|
| 153 |
+
" for button_idx, button in enumerate(type_buttons, 1):\n",
|
| 154 |
+
" btn_id = f\"btn_{app_type}_{button_idx}\"\n",
|
| 155 |
+
" css = css_template.format(btn_id=btn_id, image_url=button.image_url)\n",
|
| 156 |
+
" all_css.append(css)\n",
|
| 157 |
" \n",
|
| 158 |
" return \"\\n\".join(all_css)"
|
| 159 |
]
|
|
|
|
| 161 |
{
|
| 162 |
"cell_type": "code",
|
| 163 |
"execution_count": null,
|
| 164 |
+
"metadata": {
|
| 165 |
+
"vscode": {
|
| 166 |
+
"languageId": "python"
|
| 167 |
+
}
|
| 168 |
+
},
|
| 169 |
"outputs": [
|
| 170 |
{
|
| 171 |
"ename": "NameError",
|
|
|
|
| 193 |
{
|
| 194 |
"cell_type": "code",
|
| 195 |
"execution_count": null,
|
| 196 |
+
"metadata": {
|
| 197 |
+
"vscode": {
|
| 198 |
+
"languageId": "python"
|
| 199 |
+
}
|
| 200 |
+
},
|
| 201 |
"outputs": [
|
| 202 |
{
|
| 203 |
"ename": "NameError",
|
|
|
|
| 224 |
" Button(\"Search\", \"img.jpg\", \"https://search.com\", \"Search\")\n",
|
| 225 |
" ]\n",
|
| 226 |
" css = generate_css(buttons)\n",
|
| 227 |
+
" test('#btn_ai_1', css.lower(), lambda x,y: x in y)\n",
|
| 228 |
+
" test('#btn_search_1', css.lower(), lambda x,y: x in y)\n",
|
| 229 |
"\n",
|
| 230 |
"test_generate_css()"
|
| 231 |
]
|
|
|
|
| 233 |
{
|
| 234 |
"cell_type": "code",
|
| 235 |
"execution_count": null,
|
| 236 |
+
"metadata": {
|
| 237 |
+
"vscode": {
|
| 238 |
+
"languageId": "python"
|
| 239 |
+
}
|
| 240 |
+
},
|
| 241 |
"outputs": [],
|
| 242 |
"source": [
|
| 243 |
"#| hide\n",
|
nbs/02_gradio_app.ipynb
CHANGED
|
@@ -16,7 +16,11 @@
|
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
"execution_count": null,
|
| 19 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"outputs": [],
|
| 21 |
"source": [
|
| 22 |
"#| default_exp gradio_app"
|
|
@@ -25,7 +29,11 @@
|
|
| 25 |
{
|
| 26 |
"cell_type": "code",
|
| 27 |
"execution_count": null,
|
| 28 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"outputs": [
|
| 30 |
{
|
| 31 |
"ename": "ModuleNotFoundError",
|
|
@@ -43,6 +51,8 @@
|
|
| 43 |
"#| export\n",
|
| 44 |
"#| hide\n",
|
| 45 |
"import gradio as gr\n",
|
|
|
|
|
|
|
| 46 |
"from app_starter_gui.core import Button, load_buttons\n",
|
| 47 |
"from app_starter_gui.css import generate_css"
|
| 48 |
]
|
|
@@ -50,7 +60,11 @@
|
|
| 50 |
{
|
| 51 |
"cell_type": "code",
|
| 52 |
"execution_count": null,
|
| 53 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
"outputs": [],
|
| 55 |
"source": [
|
| 56 |
"#| hide\n",
|
|
@@ -60,7 +74,11 @@
|
|
| 60 |
{
|
| 61 |
"cell_type": "code",
|
| 62 |
"execution_count": null,
|
| 63 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
"outputs": [],
|
| 65 |
"source": [
|
| 66 |
"#| export\n",
|
|
@@ -75,23 +93,39 @@
|
|
| 75 |
" \"\"\"\n",
|
| 76 |
" buttons = load_buttons(yaml_file)\n",
|
| 77 |
" css = generate_css(buttons)\n",
|
|
|
|
|
|
|
|
|
|
| 78 |
" \n",
|
| 79 |
" with gr.Blocks(css=css) as blocks:\n",
|
| 80 |
-
"
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
" return blocks"
|
| 89 |
]
|
| 90 |
},
|
| 91 |
{
|
| 92 |
"cell_type": "code",
|
| 93 |
"execution_count": null,
|
| 94 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
"outputs": [],
|
| 96 |
"source": [
|
| 97 |
"# Example usage\n",
|
|
@@ -101,7 +135,11 @@
|
|
| 101 |
{
|
| 102 |
"cell_type": "code",
|
| 103 |
"execution_count": null,
|
| 104 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
"outputs": [],
|
| 106 |
"source": [
|
| 107 |
"#| export\n",
|
|
@@ -119,7 +157,11 @@
|
|
| 119 |
{
|
| 120 |
"cell_type": "code",
|
| 121 |
"execution_count": null,
|
| 122 |
-
"metadata": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
"outputs": [],
|
| 124 |
"source": [
|
| 125 |
"#| hide\n",
|
|
|
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
"execution_count": null,
|
| 19 |
+
"metadata": {
|
| 20 |
+
"vscode": {
|
| 21 |
+
"languageId": "python"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
"outputs": [],
|
| 25 |
"source": [
|
| 26 |
"#| default_exp gradio_app"
|
|
|
|
| 29 |
{
|
| 30 |
"cell_type": "code",
|
| 31 |
"execution_count": null,
|
| 32 |
+
"metadata": {
|
| 33 |
+
"vscode": {
|
| 34 |
+
"languageId": "python"
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
"outputs": [
|
| 38 |
{
|
| 39 |
"ename": "ModuleNotFoundError",
|
|
|
|
| 51 |
"#| export\n",
|
| 52 |
"#| hide\n",
|
| 53 |
"import gradio as gr\n",
|
| 54 |
+
"from itertools import groupby\n",
|
| 55 |
+
"from operator import attrgetter\n",
|
| 56 |
"from app_starter_gui.core import Button, load_buttons\n",
|
| 57 |
"from app_starter_gui.css import generate_css"
|
| 58 |
]
|
|
|
|
| 60 |
{
|
| 61 |
"cell_type": "code",
|
| 62 |
"execution_count": null,
|
| 63 |
+
"metadata": {
|
| 64 |
+
"vscode": {
|
| 65 |
+
"languageId": "python"
|
| 66 |
+
}
|
| 67 |
+
},
|
| 68 |
"outputs": [],
|
| 69 |
"source": [
|
| 70 |
"#| hide\n",
|
|
|
|
| 74 |
{
|
| 75 |
"cell_type": "code",
|
| 76 |
"execution_count": null,
|
| 77 |
+
"metadata": {
|
| 78 |
+
"vscode": {
|
| 79 |
+
"languageId": "python"
|
| 80 |
+
}
|
| 81 |
+
},
|
| 82 |
"outputs": [],
|
| 83 |
"source": [
|
| 84 |
"#| export\n",
|
|
|
|
| 93 |
" \"\"\"\n",
|
| 94 |
" buttons = load_buttons(yaml_file)\n",
|
| 95 |
" css = generate_css(buttons)\n",
|
| 96 |
+
"\n",
|
| 97 |
+
" buttons_sorted = sorted(buttons, key=attrgetter('app_type'))\n",
|
| 98 |
+
" button_groups = {k: list(g) for k, g in groupby(buttons_sorted, key=attrgetter('app_type'))}\n",
|
| 99 |
" \n",
|
| 100 |
" with gr.Blocks(css=css) as blocks:\n",
|
| 101 |
+
" with gr.Row():\n",
|
| 102 |
+
" # Create a column for each app_type\n",
|
| 103 |
+
" for app_type, type_buttons in button_groups.items():\n",
|
| 104 |
+
" with gr.Column():\n",
|
| 105 |
+
" gr.Markdown(f\"### {app_type}\")\n",
|
| 106 |
+
" for button_idx, button in enumerate(type_buttons):\n",
|
| 107 |
+
" btn = gr.Button(\n",
|
| 108 |
+
" value=button.label,\n",
|
| 109 |
+
" elem_id=f\"btn_{app_type}_{button_idx}\", # Make unique ID for each button\n",
|
| 110 |
+
" scale=1,\n",
|
| 111 |
+
" )\n",
|
| 112 |
+
" btn.click(\n",
|
| 113 |
+
" fn=None, \n",
|
| 114 |
+
" inputs=None, \n",
|
| 115 |
+
" outputs=None,\n",
|
| 116 |
+
" js=f\"() => {{ window.open('{button.link_url}', '_blank'); }}\"\n",
|
| 117 |
+
" )\n",
|
| 118 |
" return blocks"
|
| 119 |
]
|
| 120 |
},
|
| 121 |
{
|
| 122 |
"cell_type": "code",
|
| 123 |
"execution_count": null,
|
| 124 |
+
"metadata": {
|
| 125 |
+
"vscode": {
|
| 126 |
+
"languageId": "python"
|
| 127 |
+
}
|
| 128 |
+
},
|
| 129 |
"outputs": [],
|
| 130 |
"source": [
|
| 131 |
"# Example usage\n",
|
|
|
|
| 135 |
{
|
| 136 |
"cell_type": "code",
|
| 137 |
"execution_count": null,
|
| 138 |
+
"metadata": {
|
| 139 |
+
"vscode": {
|
| 140 |
+
"languageId": "python"
|
| 141 |
+
}
|
| 142 |
+
},
|
| 143 |
"outputs": [],
|
| 144 |
"source": [
|
| 145 |
"#| export\n",
|
|
|
|
| 157 |
{
|
| 158 |
"cell_type": "code",
|
| 159 |
"execution_count": null,
|
| 160 |
+
"metadata": {
|
| 161 |
+
"vscode": {
|
| 162 |
+
"languageId": "python"
|
| 163 |
+
}
|
| 164 |
+
},
|
| 165 |
"outputs": [],
|
| 166 |
"source": [
|
| 167 |
"#| hide\n",
|
test.ipynb
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 3,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"from app_starter_gui.css import generate_css\n",
|
| 10 |
+
"from app_starter_gui.core import Button, load_buttons"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"cell_type": "code",
|
| 15 |
+
"execution_count": 4,
|
| 16 |
+
"metadata": {},
|
| 17 |
+
"outputs": [],
|
| 18 |
+
"source": [
|
| 19 |
+
"yaml_file = \"buttons.yaml\"\n",
|
| 20 |
+
"buttons = load_buttons(yaml_file)\n",
|
| 21 |
+
"css = generate_css(buttons)"
|
| 22 |
+
]
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"cell_type": "code",
|
| 26 |
+
"execution_count": 6,
|
| 27 |
+
"metadata": {},
|
| 28 |
+
"outputs": [
|
| 29 |
+
{
|
| 30 |
+
"name": "stdout",
|
| 31 |
+
"output_type": "stream",
|
| 32 |
+
"text": [
|
| 33 |
+
"\n",
|
| 34 |
+
" #btn1 { \n",
|
| 35 |
+
" height: 230px; /* Total height of button */\n",
|
| 36 |
+
" width: 200px;\n",
|
| 37 |
+
" border-radius: 15px;\n",
|
| 38 |
+
" display: flex;\n",
|
| 39 |
+
" flex-direction: column;\n",
|
| 40 |
+
" padding: 0;\n",
|
| 41 |
+
" margin: 0;\n",
|
| 42 |
+
" overflow: hidden;\n",
|
| 43 |
+
" transition: transform 0.2s, box-shadow 0.2s;\n",
|
| 44 |
+
" background: none;\n",
|
| 45 |
+
" }\n",
|
| 46 |
+
" \n",
|
| 47 |
+
" #btn1::before {\n",
|
| 48 |
+
" content: '';\n",
|
| 49 |
+
" height: 180px; /* Image height */\n",
|
| 50 |
+
" width: 100%;\n",
|
| 51 |
+
" background-size: cover;\n",
|
| 52 |
+
" background-position: center center;\n",
|
| 53 |
+
" background-repeat: no-repeat;\n",
|
| 54 |
+
" background-image: url('https://github.com/danielmiessler/fabric/blob/main/images/fabric-logo-gif.gif?raw=true');\n",
|
| 55 |
+
" transition: transform 0.2s;\n",
|
| 56 |
+
" margin: 0;\n",
|
| 57 |
+
" padding: 0;\n",
|
| 58 |
+
" display: block;\n",
|
| 59 |
+
" flex-shrink: 0;\n",
|
| 60 |
+
" position: relative;\n",
|
| 61 |
+
" top: 0;\n",
|
| 62 |
+
" border-radius: 15px 15px 0 0; /* Round top corners only */\n",
|
| 63 |
+
" }\n",
|
| 64 |
+
" \n",
|
| 65 |
+
" #btn1:hover {\n",
|
| 66 |
+
" transform: translateY(-5px);\n",
|
| 67 |
+
" box-shadow: 0 5px 15px rgba(0,0,0,0.3);\n",
|
| 68 |
+
" }\n",
|
| 69 |
+
"\n",
|
| 70 |
+
" #btn1 > div {\n",
|
| 71 |
+
" height: 50px;\n",
|
| 72 |
+
" display: flex;\n",
|
| 73 |
+
" align-items: center;\n",
|
| 74 |
+
" justify-content: center;\n",
|
| 75 |
+
" }\n",
|
| 76 |
+
"\n",
|
| 77 |
+
" #btn1:hover::before {\n",
|
| 78 |
+
" transform: scale(1.05);\n",
|
| 79 |
+
" }\n",
|
| 80 |
+
" \n",
|
| 81 |
+
"\n",
|
| 82 |
+
" #btn2 { \n",
|
| 83 |
+
" height: 230px; /* Total height of button */\n",
|
| 84 |
+
" width: 200px;\n",
|
| 85 |
+
" border-radius: 15px;\n",
|
| 86 |
+
" display: flex;\n",
|
| 87 |
+
" flex-direction: column;\n",
|
| 88 |
+
" padding: 0;\n",
|
| 89 |
+
" margin: 0;\n",
|
| 90 |
+
" overflow: hidden;\n",
|
| 91 |
+
" transition: transform 0.2s, box-shadow 0.2s;\n",
|
| 92 |
+
" background: none;\n",
|
| 93 |
+
" }\n",
|
| 94 |
+
" \n",
|
| 95 |
+
" #btn2::before {\n",
|
| 96 |
+
" content: '';\n",
|
| 97 |
+
" height: 180px; /* Image height */\n",
|
| 98 |
+
" width: 100%;\n",
|
| 99 |
+
" background-size: cover;\n",
|
| 100 |
+
" background-position: center center;\n",
|
| 101 |
+
" background-repeat: no-repeat;\n",
|
| 102 |
+
" background-image: url('https://static1.srcdn.com/wordpress/wp-content/uploads/2020/06/Gloomhaven-Jaws-of-the-Lion-Hatchet.jpg');\n",
|
| 103 |
+
" transition: transform 0.2s;\n",
|
| 104 |
+
" margin: 0;\n",
|
| 105 |
+
" padding: 0;\n",
|
| 106 |
+
" display: block;\n",
|
| 107 |
+
" flex-shrink: 0;\n",
|
| 108 |
+
" position: relative;\n",
|
| 109 |
+
" top: 0;\n",
|
| 110 |
+
" border-radius: 15px 15px 0 0; /* Round top corners only */\n",
|
| 111 |
+
" }\n",
|
| 112 |
+
" \n",
|
| 113 |
+
" #btn2:hover {\n",
|
| 114 |
+
" transform: translateY(-5px);\n",
|
| 115 |
+
" box-shadow: 0 5px 15px rgba(0,0,0,0.3);\n",
|
| 116 |
+
" }\n",
|
| 117 |
+
"\n",
|
| 118 |
+
" #btn2 > div {\n",
|
| 119 |
+
" height: 50px;\n",
|
| 120 |
+
" display: flex;\n",
|
| 121 |
+
" align-items: center;\n",
|
| 122 |
+
" justify-content: center;\n",
|
| 123 |
+
" }\n",
|
| 124 |
+
"\n",
|
| 125 |
+
" #btn2:hover::before {\n",
|
| 126 |
+
" transform: scale(1.05);\n",
|
| 127 |
+
" }\n",
|
| 128 |
+
" \n"
|
| 129 |
+
]
|
| 130 |
+
}
|
| 131 |
+
],
|
| 132 |
+
"source": [
|
| 133 |
+
"print(css)"
|
| 134 |
+
]
|
| 135 |
+
}
|
| 136 |
+
],
|
| 137 |
+
"metadata": {
|
| 138 |
+
"kernelspec": {
|
| 139 |
+
"display_name": ".venv",
|
| 140 |
+
"language": "python",
|
| 141 |
+
"name": "python3"
|
| 142 |
+
},
|
| 143 |
+
"language_info": {
|
| 144 |
+
"codemirror_mode": {
|
| 145 |
+
"name": "ipython",
|
| 146 |
+
"version": 3
|
| 147 |
+
},
|
| 148 |
+
"file_extension": ".py",
|
| 149 |
+
"mimetype": "text/x-python",
|
| 150 |
+
"name": "python",
|
| 151 |
+
"nbconvert_exporter": "python",
|
| 152 |
+
"pygments_lexer": "ipython3",
|
| 153 |
+
"version": "3.11.0rc1"
|
| 154 |
+
}
|
| 155 |
+
},
|
| 156 |
+
"nbformat": 4,
|
| 157 |
+
"nbformat_minor": 2
|
| 158 |
+
}
|