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