Spaces:
Runtime error
Runtime error
File size: 2,091 Bytes
5d4bada c0e1d5b e9a1e2d 5d4bada 458c769 5d4bada e9a1e2d 5d4bada e9a1e2d 5d4bada e9a1e2d 458c769 e9a1e2d 5d4bada 487c04d e9a1e2d 487c04d e9a1e2d 5d4bada 487c04d e9a1e2d 5d4bada 487c04d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import time
import gradio as gr
import os
import numpy as np
from PIL import Image
import math
from collections import defaultdict
import os
from huggingface_hub import HfApi, hf_hub_download
HUB_TOKEN = os.getenv("HUB_TOKEN")
REPO_ID = "simenv-explorer/shapenetcore-glb"
def get_dataset_classes():
hf_api = HfApi()
info = hf_api.dataset_info(repo_id=REPO_ID, token=HUB_TOKEN)
dataset_classes = defaultdict(list)
for file in info.siblings:
if ".glb" in file.rfilename:
class_name = file.rfilename.split("/")[0]
dataset_classes[class_name].append(file.rfilename)
print(dataset_classes)
return dataset_classes
dataset_dict = get_dataset_classes()
dataset_classes = list(dataset_dict.keys())
default_models = dataset_dict[dataset_classes[0]]
def load_mesh(mesh_file_name):
return mesh_file_name, mesh_file_name
def update(asset_name):
# wget the glb file from the datasets repo
split_model_path = asset_name.split("/")
asset_path = hf_hub_download(
repo_id=REPO_ID,
filename=split_model_path[1],
subfolder=split_model_path[0],
repo_type="dataset",
use_auth_token=HUB_TOKEN,
)
print(asset_name)
return asset_path
def update_models(class_name):
model_choices = dataset_dict[class_name]
return gr.Dropdown.update(choices=model_choices)
def update_model_list(class_name):
model_choices = dataset_dict[class_name]
return gr.Dropdown.update(choices=model_choices)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
inp = gr.Dropdown(choices=dataset_classes, interactive=True, label="3D Model Class", value=dataset_classes[0])
out1 = gr.Dropdown(choices=default_models, interactive=True, label="3D Model", value=default_models[0])
out2 = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
inp.change(fn=update_model_list, inputs=inp, outputs=out1)
inp.change(fn=update, inputs=out1, outputs=out2)
out1.change(fn=update, inputs=out1, outputs=out2)
demo.launch()
|