Spaces:
Running
Running
import gradio as gr | |
import os | |
def load_mesh_with_info(mesh_file): | |
if not mesh_file: | |
return None, "No file selected" | |
file_size = os.path.getsize(mesh_file) / 1024 | |
return mesh_file, f"File: {os.path.basename(mesh_file)}, Size: {file_size:.2f} KB" | |
files_dir = "files" | |
model_files = [ | |
"model1.glb", | |
"model2.glb", | |
"model3.glb", | |
"model4.glb" | |
] | |
for model_file in model_files: | |
file_path = os.path.join(files_dir, model_file) | |
if not os.path.exists(file_path): | |
print(f"Error: {file_path} does not exist.") | |
else: | |
print(f"Found: {file_path}") | |
with gr.Blocks() as demo: | |
gr.Markdown( | |
""" | |
# [Three](https://huggingface.co/spaces/sudo-soldier/three) | |
""" | |
) | |
with gr.Row(): | |
model_input = gr.Model3D(label="Upload a 3D Model") | |
file_info = gr.Text(label="File Info") | |
model_output = gr.Model3D(clear_color=[0.1, 0.1, 0.1, 1.0], label="Preview Model") | |
def handle_model_input(selected_model): | |
if selected_model: | |
file_info_str = f"File: {os.path.basename(selected_model)}, Size: {os.path.getsize(selected_model) / 1024:.2f} KB" | |
return selected_model, file_info_str | |
model_input.change(handle_model_input, inputs=model_input, outputs=[model_output, file_info]) | |
examples = gr.Examples( | |
examples=[ | |
[os.path.join(files_dir, "model1.glb")], | |
[os.path.join(files_dir, "model2.glb")], | |
[os.path.join(files_dir, "model3.glb")], | |
[os.path.join(files_dir, "model4.glb")] | |
], | |
inputs=model_input, | |
outputs=[model_output, file_info] | |
) | |
if __name__ == "__main__": | |
demo.launch() | |