Change startup parameters
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import modules.version_info as version_info
|
| 3 |
|
| 4 |
def getVersions():
|
|
@@ -23,12 +24,10 @@ def load_data(query_params, model_3d, image_slider):
|
|
| 23 |
|
| 24 |
def process_upload(files):
|
| 25 |
"""
|
| 26 |
-
Process uploaded files and assign them to the
|
| 27 |
-
|
| 28 |
-
Files with extensions in [".
|
| 29 |
-
|
| 30 |
-
Files with extensions in [".png", ".jpg", ".jpeg"] are
|
| 31 |
-
sent to the ImageSlider component.
|
| 32 |
"""
|
| 33 |
model_file = None
|
| 34 |
image_files = []
|
|
@@ -40,9 +39,11 @@ def process_upload(files):
|
|
| 40 |
file_name = f.name if hasattr(f, "name") else f
|
| 41 |
ext = os.path.splitext(file_name)[1].lower()
|
| 42 |
if ext in [".glb", ".gltf", ".obj", ".ply"]:
|
| 43 |
-
model_file
|
|
|
|
| 44 |
elif ext in [".png", ".jpg", ".jpeg"]:
|
| 45 |
-
image_files
|
|
|
|
| 46 |
return model_file, image_files
|
| 47 |
|
| 48 |
gr.set_static_paths(paths=["images/", "models/", "assets/"])
|
|
@@ -54,18 +55,22 @@ with gr.Blocks(css_paths="style_20250314.css", title="3D viewer", theme='Surn/Be
|
|
| 54 |
model_3d = gr.Model3D(
|
| 55 |
label="3D Model",
|
| 56 |
value=None,
|
| 57 |
-
height=
|
|
|
|
| 58 |
)
|
| 59 |
image_slider = gr.ImageSlider(
|
| 60 |
-
label="Images",
|
| 61 |
value=None,
|
| 62 |
-
height=
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
upload_btn = gr.UploadButton(
|
| 67 |
"Upload",
|
| 68 |
-
file_types=[".glb", ".gltf", ".obj", ".png", ".jpg", ".ply"]
|
|
|
|
|
|
|
| 69 |
)
|
| 70 |
with gr.Row():
|
| 71 |
gr.HTML(value=getVersions(), visible=True, elem_id="versions")
|
|
@@ -91,5 +96,5 @@ with gr.Blocks(css_paths="style_20250314.css", title="3D viewer", theme='Surn/Be
|
|
| 91 |
if __name__ == "__main__":
|
| 92 |
viewer3d.launch(
|
| 93 |
allowed_paths=["assets", "assets/", "./assets", "images/", "./images", 'e:/TMP', 'models/'],
|
| 94 |
-
favicon_path="./assets/favicon.ico"
|
| 95 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
import modules.version_info as version_info
|
| 4 |
|
| 5 |
def getVersions():
|
|
|
|
| 24 |
|
| 25 |
def process_upload(files):
|
| 26 |
"""
|
| 27 |
+
Process uploaded files and assign them to the appropriate component based on file extension.
|
| 28 |
+
Files with extensions in [".glb", ".gltf", ".obj", ".ply"] are sent to the Model3D component.
|
| 29 |
+
Files with extensions in [".png", ".jpg", ".jpeg"] are sent to the ImageSlider component.
|
| 30 |
+
Limits: 1 file for the 3D model and up to 2 files for the image slider.
|
|
|
|
|
|
|
| 31 |
"""
|
| 32 |
model_file = None
|
| 33 |
image_files = []
|
|
|
|
| 39 |
file_name = f.name if hasattr(f, "name") else f
|
| 40 |
ext = os.path.splitext(file_name)[1].lower()
|
| 41 |
if ext in [".glb", ".gltf", ".obj", ".ply"]:
|
| 42 |
+
if not model_file: # limit to one model file
|
| 43 |
+
model_file = file_name
|
| 44 |
elif ext in [".png", ".jpg", ".jpeg"]:
|
| 45 |
+
if len(image_files) < 2: # limit to two image files
|
| 46 |
+
image_files.append(file_name)
|
| 47 |
return model_file, image_files
|
| 48 |
|
| 49 |
gr.set_static_paths(paths=["images/", "models/", "assets/"])
|
|
|
|
| 55 |
model_3d = gr.Model3D(
|
| 56 |
label="3D Model",
|
| 57 |
value=None,
|
| 58 |
+
height=480,
|
| 59 |
+
elem_id="model_3d", key="model_3d"
|
| 60 |
)
|
| 61 |
image_slider = gr.ImageSlider(
|
| 62 |
+
label="2D Images",
|
| 63 |
value=None,
|
| 64 |
+
height=480,
|
| 65 |
+
elem_id="image_slider", key="image_slider"
|
| 66 |
)
|
| 67 |
|
| 68 |
with gr.Row():
|
| 69 |
upload_btn = gr.UploadButton(
|
| 70 |
"Upload",
|
| 71 |
+
file_types=[".glb", ".gltf", ".obj", ".png", ".jpg", ".ply"],
|
| 72 |
+
file_count="multiple",
|
| 73 |
+
elem_id="upload_btn", key="upload_btn",
|
| 74 |
)
|
| 75 |
with gr.Row():
|
| 76 |
gr.HTML(value=getVersions(), visible=True, elem_id="versions")
|
|
|
|
| 96 |
if __name__ == "__main__":
|
| 97 |
viewer3d.launch(
|
| 98 |
allowed_paths=["assets", "assets/", "./assets", "images/", "./images", 'e:/TMP', 'models/'],
|
| 99 |
+
favicon_path="./assets/favicon.ico", show_api=False, strict_cors=False
|
| 100 |
)
|