Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,97 @@
|
|
| 1 |
#!/usr/bin/env python3
|
|
|
|
| 2 |
import sys
|
|
|
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
if not
|
| 11 |
-
return "⚠️ No
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
demo = gr.Interface(
|
| 17 |
-
fn=
|
| 18 |
-
inputs=gr.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
| 25 |
-
print("="
|
| 26 |
-
print("🚀 Starting
|
| 27 |
-
print("="
|
| 28 |
-
|
| 29 |
demo.launch(
|
| 30 |
server_name="0.0.0.0",
|
| 31 |
server_port=7860,
|
| 32 |
share=False,
|
| 33 |
show_error=True,
|
| 34 |
-
debug=True
|
| 35 |
-
)
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
import sys
|
| 4 |
+
import os
|
| 5 |
import gradio as gr
|
| 6 |
+
import trimesh
|
| 7 |
+
import numpy as np
|
| 8 |
|
| 9 |
+
def process_obj_file(file_obj):
|
| 10 |
+
"""
|
| 11 |
+
Process OBJ file and return first 10 lines of analysis results
|
| 12 |
+
"""
|
| 13 |
+
sys.stdout.flush()
|
| 14 |
+
print(f"[DEBUG] Processing file: {file_obj.name if file_obj else 'None'}", flush=True)
|
| 15 |
|
| 16 |
+
if not file_obj:
|
| 17 |
+
return "⚠️ No file provided"
|
| 18 |
|
| 19 |
+
try:
|
| 20 |
+
results = []
|
| 21 |
+
results.append("="*60)
|
| 22 |
+
results.append("OBJ FILE ANALYSIS - First 10 Lines of Results")
|
| 23 |
+
results.append("="*60)
|
| 24 |
+
|
| 25 |
+
# Read raw OBJ file first 10 lines
|
| 26 |
+
results.append("\n📄 RAW OBJ FILE (First 10 Lines):")
|
| 27 |
+
results.append("-"*60)
|
| 28 |
+
with open(file_obj.name, 'r') as f:
|
| 29 |
+
for i, line in enumerate(f):
|
| 30 |
+
if i >= 10:
|
| 31 |
+
break
|
| 32 |
+
results.append(f"Line {i+1}: {line.rstrip()}")
|
| 33 |
+
|
| 34 |
+
# Load mesh using trimesh
|
| 35 |
+
results.append("\n🔷 MESH ANALYSIS:")
|
| 36 |
+
results.append("-"*60)
|
| 37 |
+
|
| 38 |
+
mesh = trimesh.load(file_obj.name, force='mesh')
|
| 39 |
+
|
| 40 |
+
# Check if it's a Scene or Mesh
|
| 41 |
+
if isinstance(mesh, trimesh.Scene):
|
| 42 |
+
results.append(f"Type: Scene with {len(mesh.geometry)} geometries")
|
| 43 |
+
# Get the first geometry
|
| 44 |
+
if len(mesh.geometry) > 0:
|
| 45 |
+
first_geom_name = list(mesh.geometry.keys())[0]
|
| 46 |
+
mesh = mesh.geometry[first_geom_name]
|
| 47 |
+
results.append(f"Using first geometry: {first_geom_name}")
|
| 48 |
+
|
| 49 |
+
# Mesh statistics (ensures we don't exceed 10 total result lines)
|
| 50 |
+
results.append(f"Vertices: {len(mesh.vertices)}")
|
| 51 |
+
results.append(f"Faces: {len(mesh.faces)}")
|
| 52 |
+
results.append(f"Is Watertight: {mesh.is_watertight}")
|
| 53 |
+
results.append(f"Is Winding Consistent: {mesh.is_winding_consistent}")
|
| 54 |
+
results.append(f"Bounds: {mesh.bounds.tolist()}")
|
| 55 |
+
results.append(f"Center Mass: {mesh.center_mass.tolist()}")
|
| 56 |
+
|
| 57 |
+
# Join results
|
| 58 |
+
output = "\n".join(results[:25]) # Limit output
|
| 59 |
+
|
| 60 |
+
print("[DEBUG] Processing completed successfully", flush=True)
|
| 61 |
+
return output
|
| 62 |
+
|
| 63 |
+
except Exception as e:
|
| 64 |
+
error_msg = f"❌ Error processing file: {str(e)}\n\nStacktrace:\n{sys.exc_info()}"
|
| 65 |
+
print(error_msg, flush=True)
|
| 66 |
+
return error_msg
|
| 67 |
|
| 68 |
+
# Gradio Interface
|
| 69 |
demo = gr.Interface(
|
| 70 |
+
fn=process_obj_file,
|
| 71 |
+
inputs=gr.File(
|
| 72 |
+
label="Upload OBJ File",
|
| 73 |
+
file_types=[".obj"],
|
| 74 |
+
type="filepath"
|
| 75 |
+
),
|
| 76 |
+
outputs=gr.Textbox(
|
| 77 |
+
label="Analysis Results (First 10 Lines)",
|
| 78 |
+
lines=20,
|
| 79 |
+
max_lines=30
|
| 80 |
+
),
|
| 81 |
+
title="🔷 OBJ File Analyzer",
|
| 82 |
+
description="Upload a 3D OBJ file to see the first 10 lines of raw content and mesh analysis",
|
| 83 |
+
examples=None,
|
| 84 |
+
cache_examples=False
|
| 85 |
)
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
| 88 |
+
print("="*60, flush=True)
|
| 89 |
+
print("🚀 Starting OBJ File Analyzer...", flush=True)
|
| 90 |
+
print("="*60, flush=True)
|
|
|
|
| 91 |
demo.launch(
|
| 92 |
server_name="0.0.0.0",
|
| 93 |
server_port=7860,
|
| 94 |
share=False,
|
| 95 |
show_error=True,
|
| 96 |
+
debug=True
|
| 97 |
+
)
|