ckc99u commited on
Commit
0e45a5a
·
verified ·
1 Parent(s): 2addbd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -19
app.py CHANGED
@@ -1,35 +1,97 @@
1
  #!/usr/bin/env python3
 
2
  import sys
 
3
  import gradio as gr
 
 
4
 
5
- def echo_text(text):
6
- """Simple echo function for debugging"""
7
- sys.stdout.flush() # Force flush
8
- print(f"[DEBUG] Function called with: {text}", flush=True)
 
 
9
 
10
- if not text:
11
- return "⚠️ No text provided"
12
 
13
- return f"✅ Echo: {text}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # Minimal interface
16
  demo = gr.Interface(
17
- fn=echo_text,
18
- inputs=gr.Textbox(label="Input Text", placeholder="Type something..."),
19
- outputs=gr.Textbox(label="Output"),
20
- title="🧪 Text Echo Test",
21
- description="Simple echo test to verify Gradio is working"
 
 
 
 
 
 
 
 
 
 
22
  )
23
 
24
  if __name__ == "__main__":
25
- print("=" * 60, flush=True)
26
- print("🚀 Starting text echo test...", flush=True)
27
- print("=" * 60, flush=True)
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 # Enable debug mode
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
+ )