Spaces:
Runtime error
Runtime error
Download model from hub
Browse files
app.py
CHANGED
@@ -11,11 +11,11 @@ from huggingface_hub import HfApi, hf_hub_download
|
|
11 |
|
12 |
|
13 |
HUB_TOKEN = os.getenv("HUB_TOKEN")
|
14 |
-
|
15 |
|
16 |
def get_dataset_classes():
|
17 |
hf_api = HfApi()
|
18 |
-
info = hf_api.dataset_info(repo_id=
|
19 |
dataset_classes = defaultdict(list)
|
20 |
|
21 |
for file in info.siblings:
|
@@ -36,20 +36,28 @@ def load_mesh(mesh_file_name):
|
|
36 |
return mesh_file_name, mesh_file_name
|
37 |
|
38 |
|
39 |
-
def update(
|
40 |
# wget the glb file from the datasets repo
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
def update_models(class_name):
|
46 |
-
model_choices =
|
47 |
return gr.Dropdown.update(choices=model_choices)
|
48 |
|
49 |
|
50 |
-
def update_model_list(
|
51 |
-
|
52 |
-
return
|
53 |
|
54 |
|
55 |
with gr.Blocks() as demo:
|
@@ -59,13 +67,9 @@ with gr.Blocks() as demo:
|
|
59 |
out1 = gr.Dropdown(choices=default_models, interactive=True, label="3D Model", value=default_models[0])
|
60 |
out2 = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
|
61 |
|
62 |
-
inp.change(fn=
|
63 |
-
inp.change(fn=update, inputs=
|
64 |
-
out1.change(
|
65 |
-
fn=load_mesh,
|
66 |
-
inputs=gr.Model3D(),
|
67 |
-
outputs=[gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"), gr.File(label="Download 3D Model")]
|
68 |
-
)
|
69 |
|
70 |
|
71 |
demo.launch()
|
|
|
11 |
|
12 |
|
13 |
HUB_TOKEN = os.getenv("HUB_TOKEN")
|
14 |
+
REPO_ID = "simenv-explorer/shapenetcore-glb"
|
15 |
|
16 |
def get_dataset_classes():
|
17 |
hf_api = HfApi()
|
18 |
+
info = hf_api.dataset_info(repo_id=REPO_ID, token=HUB_TOKEN)
|
19 |
dataset_classes = defaultdict(list)
|
20 |
|
21 |
for file in info.siblings:
|
|
|
36 |
return mesh_file_name, mesh_file_name
|
37 |
|
38 |
|
39 |
+
def update(asset_name):
|
40 |
# wget the glb file from the datasets repo
|
41 |
+
split_model_path = asset_name.split("/")
|
42 |
+
asset_path = hf_hub_download(
|
43 |
+
repo_id=REPO_ID,
|
44 |
+
filename=split_model_path[1],
|
45 |
+
subfolder=split_model_path[0],
|
46 |
+
repo_type="dataset",
|
47 |
+
token=HUB_TOKEN,
|
48 |
+
)
|
49 |
+
print(asset_name)
|
50 |
+
return asset_path
|
51 |
|
52 |
|
53 |
def update_models(class_name):
|
54 |
+
model_choices = dataset_dict[class_name]
|
55 |
return gr.Dropdown.update(choices=model_choices)
|
56 |
|
57 |
|
58 |
+
def update_model_list(class_name):
|
59 |
+
model_choices = dataset_dict[class_name]
|
60 |
+
return gr.Dropdown.update(choices=model_choices)
|
61 |
|
62 |
|
63 |
with gr.Blocks() as demo:
|
|
|
67 |
out1 = gr.Dropdown(choices=default_models, interactive=True, label="3D Model", value=default_models[0])
|
68 |
out2 = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
|
69 |
|
70 |
+
inp.change(fn=update_model_list, inputs=inp, outputs=out1)
|
71 |
+
inp.change(fn=update, inputs=out1, outputs=out2)
|
72 |
+
out1.change(fn=update, inputs=out1, outputs=out2)
|
|
|
|
|
|
|
|
|
73 |
|
74 |
|
75 |
demo.launch()
|