File size: 1,729 Bytes
0a4421d |
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 |
import gradio as gr
def load_data(query_params):
model_url = query_params.get("3d", None) if query_params else None
hm_url = query_params.get("hm", None) if query_params else None
img_url = query_params.get("image", None) if query_params else None
slider_images = []
if hm_url:
slider_images.append(hm_url)
if img_url:
slider_images.append(img_url)
if slider_images == []:
slider_images = ["images/logo.png"]
return model_url, slider_images
gr.set_static_paths(paths=["images/","models/","assets/"])
with gr.Blocks(theme="Surn/Beeuty") as demo:
gr.Markdown("# 3D Model Viewer")
with gr.Row():
model_3d = gr.Model3D(
label="3D Model",
value=None, # Will be updated by the load function if a URL is provided.
height=400
)
image_slider = gr.ImageSlider(
label="Images",
value=[], # Images will be populated automatically from the query strings.
height=400
)
with gr.Row():
upload_btn = gr.UploadButton(
"Upload",
file_types=[".glb", ".gltf", ".obj", ".png", ".jpg", ".ply"]
)
# Load query parameters from the URL and update the 3D model and image slider accordingly.
demo.load(
load_data,
inputs=None,
outputs=[model_3d, image_slider],
js="""() => {
const params = Object.fromEntries(new URLSearchParams(window.location.search));
return params;
}"""
)
if __name__ == "__main__":
demo.launch(allowed_paths=["assets","assets/","./assets","images/","./images", 'e:/TMP', 'models/'], favicon_path="./assets/favicon.ico") |