TheXeos commited on
Commit
e9a1e2d
·
1 Parent(s): c0e1d5b

Download model from hub

Browse files
Files changed (1) hide show
  1. app.py +20 -16
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="simenv-explorer/shapenetcore-glb", token=HUB_TOKEN)
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(model_name):
40
  # wget the glb file from the datasets repo
41
- print(model_name)
42
- return f"{model_name}/0.glb"
 
 
 
 
 
 
 
 
43
 
44
 
45
  def update_models(class_name):
46
- model_choices = update_model_list(class_name)
47
  return gr.Dropdown.update(choices=model_choices)
48
 
49
 
50
- def update_model_list(choice_class):
51
- print(f"inp1 changed {choice_class}")
52
- return {"choices": dataset_dict[choice_class]}
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=update_models, inputs=inp, outputs=out1)
63
- inp.change(fn=update, inputs=inp, outputs=out2)
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()