Spaces:
Runtime error
Runtime error
LPX55
commited on
Commit
·
56e596b
1
Parent(s):
4cc700d
Refactor space loading functionality in space_loader_tab.py to streamline the selection and display of popular Hugging Face Spaces. Replace dropdown and button with a dynamic interface that shows the selected space directly, enhancing user experience and code clarity.
Browse files- space_loader_tab.py +10 -22
space_loader_tab.py
CHANGED
@@ -2,35 +2,23 @@ import gradio as gr
|
|
2 |
|
3 |
POPULAR_SPACES = [
|
4 |
"gradio/calculator",
|
5 |
-
"gradio/image-classification",
|
6 |
"huggingface-projects/llama-2-7b-chat",
|
7 |
-
"gradio/englishtranslator",
|
8 |
-
"gradio/blocks-gallery"
|
9 |
]
|
10 |
|
11 |
def gr_load_tab():
|
12 |
gr.Markdown("## Load a Popular Hugging Face Space (gr.load)")
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
def
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
interface = gr.load(space, src="spaces")
|
25 |
-
except Exception as e:
|
26 |
-
return gr.update(visible=True, value=f"**Error loading space:** {e}"), None
|
27 |
-
return gr.update(visible=False), interface
|
28 |
|
29 |
-
load_btn.click(
|
30 |
-
fn=load_space,
|
31 |
-
inputs=space_dropdown,
|
32 |
-
outputs=[error_box, loaded_interface]
|
33 |
-
)
|
34 |
|
35 |
def iframe_loader_tab():
|
36 |
gr.Markdown("## Load Any Hugging Face Space (iframe)")
|
|
|
2 |
|
3 |
POPULAR_SPACES = [
|
4 |
"gradio/calculator",
|
|
|
5 |
"huggingface-projects/llama-2-7b-chat",
|
|
|
|
|
6 |
]
|
7 |
|
8 |
def gr_load_tab():
|
9 |
gr.Markdown("## Load a Popular Hugging Face Space (gr.load)")
|
10 |
+
dropdown = gr.Dropdown(POPULAR_SPACES, label="Popular Spaces", value=POPULAR_SPACES[0])
|
11 |
+
space_blocks = []
|
12 |
+
for space in POPULAR_SPACES:
|
13 |
+
with gr.Column(visible=(space == POPULAR_SPACES[0])) as col:
|
14 |
+
gr.load(space, src="spaces")
|
15 |
+
space_blocks.append(col)
|
16 |
|
17 |
+
def show_space(selected):
|
18 |
+
return [gr.Column(visible=(selected == space)) for space in POPULAR_SPACES]
|
19 |
+
|
20 |
+
dropdown.change(fn=show_space, inputs=dropdown, outputs=space_blocks)
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def iframe_loader_tab():
|
24 |
gr.Markdown("## Load Any Hugging Face Space (iframe)")
|