TS447 commited on
Commit
f1cafdc
·
verified ·
1 Parent(s): c421e99

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+ import os
5
+ from core_processor import SculptorEngine
6
+
7
+ # --- 1. Load Models (GPU Start hote hi load honge) ---
8
+ print("Loading AI Models... Please wait...")
9
+ depth_estimator = pipeline("depth-estimation", model="Intel/dpt-large") # High quality depth model
10
+ engine = SculptorEngine()
11
+ print("Models Loaded Successfully!")
12
+
13
+ # --- 2. Core Processing Functions ---
14
+
15
+ def process_full_stack(input_image, enable_3d):
16
+ if input_image is None:
17
+ return None, None, None, "Please upload an image first."
18
+
19
+ try:
20
+ # Temporary save
21
+ input_path = "/tmp/input_img.png"
22
+ input_image.save(input_path)
23
+
24
+ status_msg = "🔧 Step 1/3: Cleaning & Tracing Vectors..."
25
+ yield None, None, None, status_msg
26
+
27
+ # Vector Generation
28
+ svg_path = engine.generate_vector(input_path)
29
+
30
+ status_msg = "⚙️ Step 2/3: Converting to DXF (CNC Ready)..."
31
+ yield svg_path, None, None, status_msg
32
+
33
+ # DXF Generation
34
+ dxf_path = engine.generate_dxf(svg_path)
35
+
36
+ stl_path = None
37
+ if enable_3d:
38
+ status_msg = "🧠 Step 3/3: Generating 3D Relief (AI Processing)..."
39
+ yield svg_path, dxf_path, None, status_msg
40
+
41
+ # 3D Generation
42
+ pil_img = Image.open(input_path).convert("RGB")
43
+ stl_path = engine.generate_3d_relief(pil_img, depth_estimator)
44
+
45
+ status_msg = "✅ Done! Files ready for download."
46
+ yield svg_path, dxf_path, stl_path, status_msg
47
+
48
+ except Exception as e:
49
+ yield None, None, None, f"Error: {str(e)}"
50
+
51
+ # --- 3. UI Design (Dark Theme, Professional) ---
52
+
53
+ custom_css = """
54
+ .gradio-container {
55
+ font-family: 'Inter', sans-serif;
56
+ background: #111827 !important;
57
+ color: white;
58
+ }
59
+ footer {
60
+ display: none !important;
61
+ }
62
+ """
63
+
64
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="cyan")) as demo:
65
+
66
+ gr.Markdown(
67
+ """
68
+ <div align="center">
69
+ <h1 style="font-size: 3em; font-weight: 800; color: #06b6d4;">Sculptor AI Pro</h1>
70
+ <p style="color: #9ca3af;">Convert Images to Professional CNC Vectors & 3D Reliefs</p>
71
+ </div>
72
+ """
73
+ )
74
+
75
+ with gr.Row():
76
+ with gr.Column(scale=1):
77
+ input_image = gr.Image(label="Upload Source Image", type="pil", height=400)
78
+
79
+ with gr.Accordion("⚙️ Config", open=False):
80
+ enable_3d = gr.Checkbox(label="Enable 3D Relief (STL) [Requires GPU]", value=False)
81
+
82
+ submit_btn = gr.Button("🚀 Generate Artwork", variant="primary", size="lg", scale=2)
83
+
84
+ with gr.Column(scale=1):
85
+ status = gr.Textbox(label="Status", interactive=False, value="Waiting...")
86
+
87
+ gr.Markdown("### 📂 Download Results")
88
+ out_svg = gr.File(label="Vector (SVG) - For Editing")
89
+ out_dxf = gr.File(label="CNC (DXF) - For Laser/Cutter")
90
+ out_stl = gr.File(label="3D Relief (STL) - For CNC Router")
91
+
92
+ # Event Handler with Progress Simulation
93
+ submit_btn.click(
94
+ fn=process_full_stack,
95
+ inputs=[input_image, enable_3d],
96
+ outputs=[out_svg, out_dxf, out_stl, status],
97
+ show_progress="minimal"
98
+ )
99
+
100
+ if __name__ == "__main__":
101
+ demo.launch()