Spaces:
Runtime error
Runtime error
add app script
Browse files
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
+
import math
|
8 |
+
from collections import defaultdict
|
9 |
+
import os
|
10 |
+
from huggingface_hub import HfApi
|
11 |
+
|
12 |
+
|
13 |
+
def get_dataset_classes():
|
14 |
+
hf_api = HfApi()
|
15 |
+
info = hf_api.dataset_info(repo_id="simenv-explorer/public-test")
|
16 |
+
dataset_classes = defaultdict(list)
|
17 |
+
|
18 |
+
for file in info.siblings:
|
19 |
+
if ".glb" in file.rfilename:
|
20 |
+
class_name = file.rfilename.split("/")[0]
|
21 |
+
dataset_classes[class_name].append(file.rfilename)
|
22 |
+
|
23 |
+
print(dataset_classes)
|
24 |
+
return dataset_classes
|
25 |
+
|
26 |
+
|
27 |
+
dataset_dict = get_dataset_classes()
|
28 |
+
dataset_classes = list(dataset_dict.keys())
|
29 |
+
default_models = dataset_dict[dataset_classes[0]]
|
30 |
+
|
31 |
+
|
32 |
+
def load_mesh(mesh_file_name):
|
33 |
+
return mesh_file_name, mesh_file_name
|
34 |
+
|
35 |
+
|
36 |
+
def update(model_name):
|
37 |
+
# wget the glb file from the datasets repo
|
38 |
+
print(model_name)
|
39 |
+
return f"{model_name}/0.glb"
|
40 |
+
|
41 |
+
|
42 |
+
def update_model_list(choice_class):
|
43 |
+
print(f"inp1 changed {choice_class}")
|
44 |
+
return {"choices": dataset_dict[choice_class]}
|
45 |
+
|
46 |
+
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
inp = gr.Dropdown(choices=dataset_classes, interactive=True, label="3D Model Class", value=dataset_classes[0])
|
51 |
+
out1 = gr.Dropdown(choices=default_models, interactive=True, label="3D Model", value=default_models[0])
|
52 |
+
out2 = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model")
|
53 |
+
|
54 |
+
inp.change(fn=update, inputs=inp, outputs=out2)
|
55 |
+
|
56 |
+
|
57 |
+
demo.launch()
|