Spaces:
Runtime error
Runtime error
LPX55
commited on
Commit
·
aa50c63
1
Parent(s):
9c6c4fb
Add extra tabs for external tools and buttons to load them
Browse files
app.py
CHANGED
@@ -52,6 +52,7 @@ def download_csv(result):
|
|
52 |
theme = gr.Theme.from_hub("LPX55/modal_ai")
|
53 |
|
54 |
with gr.Blocks(theme=theme, js=js_func, css=css_func) as demo:
|
|
|
55 |
with gr.Sidebar(width="25vw"):
|
56 |
gr.Image("logo.png", width=80, show_label=False)
|
57 |
gr.Markdown("""
|
@@ -64,14 +65,13 @@ with gr.Blocks(theme=theme, js=js_func, css=css_func) as demo:
|
|
64 |
- [Calculator](#calculator)
|
65 |
- [Sepia Image](#sepia-image)
|
66 |
---
|
67 |
-
[GitHub Repo](https://github.com/yourrepo) | [Docs](https://yourdocs)
|
68 |
---
|
69 |
**Tips:**
|
70 |
- Try the examples in each tab!
|
71 |
- Download your results with the button on the right.
|
72 |
-
---
|
73 |
|
74 |
-
|
75 |
""")
|
76 |
gr.Code(
|
77 |
"""from gradio_client import Client
|
@@ -81,6 +81,9 @@ print(client.predict("Alex", 5, False, api_name="/greet"))
|
|
81 |
""", language="python", label="**API Example:**"
|
82 |
)
|
83 |
gr.Button("Reset All", elem_id="reset-btn")
|
|
|
|
|
|
|
84 |
|
85 |
with gr.Tab("Greeting"):
|
86 |
gr.Markdown("## Greeting Generator")
|
@@ -128,6 +131,34 @@ print(client.predict("Alex", 5, False, api_name="/greet"))
|
|
128 |
image_output = gr.Image(label="Sepia Image")
|
129 |
sepia_btn.click(sepia, image_input, image_output)
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
gr.Markdown("""
|
132 |
---
|
133 |
## 📡 API Usage
|
|
|
52 |
theme = gr.Theme.from_hub("LPX55/modal_ai")
|
53 |
|
54 |
with gr.Blocks(theme=theme, js=js_func, css=css_func) as demo:
|
55 |
+
show_space_tab = gr.State(False)
|
56 |
with gr.Sidebar(width="25vw"):
|
57 |
gr.Image("logo.png", width=80, show_label=False)
|
58 |
gr.Markdown("""
|
|
|
65 |
- [Calculator](#calculator)
|
66 |
- [Sepia Image](#sepia-image)
|
67 |
---
|
68 |
+
### [GitHub Repo](https://github.com/yourrepo) | [Docs](https://yourdocs)
|
69 |
---
|
70 |
**Tips:**
|
71 |
- Try the examples in each tab!
|
72 |
- Download your results with the button on the right.
|
|
|
73 |
|
74 |
+
|
75 |
""")
|
76 |
gr.Code(
|
77 |
"""from gradio_client import Client
|
|
|
81 |
""", language="python", label="**API Example:**"
|
82 |
)
|
83 |
gr.Button("Reset All", elem_id="reset-btn")
|
84 |
+
load_space_btn = gr.Button("Load Extra Space", elem_id="load-space-btn")
|
85 |
+
load_sam_btn = gr.Button("Load SAM2.1 Masking Tool (gr.load)", elem_id="load-sam-btn")
|
86 |
+
load_sam_iframe_btn = gr.Button("Load SAM2.1 Masking Tool (iframe)", elem_id="load-sam-iframe-btn")
|
87 |
|
88 |
with gr.Tab("Greeting"):
|
89 |
gr.Markdown("## Greeting Generator")
|
|
|
131 |
image_output = gr.Image(label="Sepia Image")
|
132 |
sepia_btn.click(sepia, image_input, image_output)
|
133 |
|
134 |
+
with gr.Tab("Extra Space", visible=False) as extra_space_tab:
|
135 |
+
gr.Markdown("## External Gradio Space")
|
136 |
+
gr.HTML('<iframe src="https://huggingface.co/spaces/gradio/calculator" width="100%" height="600" style="border:none;"></iframe>')
|
137 |
+
|
138 |
+
with gr.Tab("SAM2.1 Masking Tool (gr.load)", visible=False) as sam_tab:
|
139 |
+
gr.Markdown("## LPX55/SAM2_1-Image-Predictor-Masking-Tool-CPU (gr.load)")
|
140 |
+
sam_interface = gr.load("LPX55/SAM2_1-Image-Predictor-Masking-Tool-CPU", src="spaces")
|
141 |
+
|
142 |
+
with gr.Tab("SAM2.1 Masking Tool (iframe)", visible=False) as sam_iframe_tab:
|
143 |
+
gr.Markdown("## LPX55/SAM2_1-Image-Predictor-Masking-Tool-CPU (iframe)")
|
144 |
+
sam_iframe = gr.HTML(visible=True)
|
145 |
+
|
146 |
+
def show_tab():
|
147 |
+
return gr.Tab(visible=True)
|
148 |
+
|
149 |
+
load_space_btn.click(fn=show_tab, outputs=[extra_space_tab])
|
150 |
+
|
151 |
+
def show_sam_tab():
|
152 |
+
return gr.Tab(visible=True)
|
153 |
+
|
154 |
+
load_sam_btn.click(fn=show_sam_tab, outputs=[sam_tab])
|
155 |
+
|
156 |
+
def show_sam_iframe_tab():
|
157 |
+
iframe_html = '<iframe src="https://lpx55-sam2-1-image-predictor-masking-tool-cpu.hf.space" width="100%" height="800" style="border:none;"></iframe>'
|
158 |
+
return gr.Tab(visible=True), iframe_html
|
159 |
+
|
160 |
+
load_sam_iframe_btn.click(fn=show_sam_iframe_tab, outputs=[sam_iframe_tab, sam_iframe])
|
161 |
+
|
162 |
gr.Markdown("""
|
163 |
---
|
164 |
## 📡 API Usage
|