3D-Viewer / app.py
Surn's picture
Initial Push
0a4421d
raw
history blame
1.73 kB
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")