Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,10 +2,18 @@ import gradio as gr
|
|
| 2 |
from genmake_engine import generate_crystal, PRODUCTS, QUALITIES
|
| 3 |
from photo_prep import auto_enhance_to_png
|
| 4 |
|
| 5 |
-
def run_engine(img_path, product, face_mode, bg_mode, quality, use_enhanced, fp16):
|
| 6 |
if img_path is None:
|
| 7 |
-
return "β οΈ Error: Please upload an image.", None, None, None
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def run_enhance(img_path):
|
| 11 |
if img_path is None:
|
|
@@ -13,59 +21,123 @@ def run_enhance(img_path):
|
|
| 13 |
orig, enh, report = auto_enhance_to_png(img_path)
|
| 14 |
return enh, report
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
with gr.Row():
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
-
with gr.
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
fp16_in = gr.Checkbox(value=True, label="Use Fast GPU (FP16)")
|
| 44 |
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
weight_out = gr.Image(type="filepath", label="Thermal Density Preview")
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
btn_enhance.click(
|
| 58 |
-
fn=run_enhance,
|
| 59 |
-
inputs=[img_in],
|
| 60 |
-
outputs=[enh_out, log_out]
|
| 61 |
-
)
|
| 62 |
|
| 63 |
btn_gen.click(
|
| 64 |
fn=run_engine,
|
| 65 |
-
inputs=[
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
| 2 |
from genmake_engine import generate_crystal, PRODUCTS, QUALITIES
|
| 3 |
from photo_prep import auto_enhance_to_png
|
| 4 |
|
| 5 |
+
def run_engine(img_path, product, face_mode, bg_mode, shape_mask, mask_scale, mask_x, mask_y, diorama_mode, quality, use_enhanced, fp16, detail_boost, depth_vol):
|
| 6 |
if img_path is None:
|
| 7 |
+
return "β οΈ Error: Please upload an image.", None, None, None, None
|
| 8 |
+
|
| 9 |
+
log, files_out, depth_png, weight_png = generate_crystal(
|
| 10 |
+
img_path, product, face_mode, bg_mode, shape_mask,
|
| 11 |
+
mask_scale, mask_x, mask_y, diorama_mode, quality,
|
| 12 |
+
use_enhanced, fp16, detail_boost, depth_vol
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
glb_path = files_out[0]
|
| 16 |
+
return log, glb_path, glb_path, depth_png, weight_png
|
| 17 |
|
| 18 |
def run_enhance(img_path):
|
| 19 |
if img_path is None:
|
|
|
|
| 21 |
orig, enh, report = auto_enhance_to_png(img_path)
|
| 22 |
return enh, report
|
| 23 |
|
| 24 |
+
# ==========================================
|
| 25 |
+
# π¨ CUSTOM LUXURY THEME (GOLD & BROWN)
|
| 26 |
+
# ==========================================
|
| 27 |
+
genmake_gold = gr.themes.Color(
|
| 28 |
+
c50="#fbf8ea", c100="#f4ebd0", c200="#ead6ad", c300="#dfbe82",
|
| 29 |
+
c400="#d4a35b", c500="#c98a3c", c600="#b36f30", c700="#955529",
|
| 30 |
+
c800="#7a4426", c900="#633821", c950="#371d0f",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
genmake_brown = gr.themes.Color(
|
| 34 |
+
c50="#fcfbf9", c100="#f3efe9", c200="#e1d8cf", c300="#c9bbae",
|
| 35 |
+
c400="#af9c8b", c500="#96806e", c600="#7a6556", c700="#625146",
|
| 36 |
+
c800="#52453d", c900="#453a34", c950="#251f1b",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
luxury_theme = gr.themes.Soft(
|
| 40 |
+
primary_hue=genmake_gold,
|
| 41 |
+
neutral_hue=genmake_brown,
|
| 42 |
+
font=[gr.themes.GoogleFont("Montserrat"), "ui-sans-serif", "system-ui", "sans-serif"]
|
| 43 |
+
).set(
|
| 44 |
+
body_background_fill="*neutral_50",
|
| 45 |
+
body_background_fill_dark="*neutral_950",
|
| 46 |
+
button_primary_background_fill="*primary_500",
|
| 47 |
+
button_primary_background_fill_hover="*primary_400",
|
| 48 |
+
button_primary_text_color="white",
|
| 49 |
+
block_title_text_color="*primary_600",
|
| 50 |
+
block_title_text_color_dark="*primary_400",
|
| 51 |
+
slider_color="*primary_500",
|
| 52 |
+
border_color_primary="*neutral_200",
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# ==========================================
|
| 56 |
+
# APP UI BUILDER
|
| 57 |
+
# ==========================================
|
| 58 |
+
with gr.Blocks(title="GenMake Command Center", theme=luxury_theme) as app:
|
| 59 |
+
|
| 60 |
+
gr.Markdown("# π GenMake F2 Ultra Command Center")
|
| 61 |
+
gr.Markdown("Direct point-cloud generation for K9 crystal subsurface engraving.")
|
| 62 |
|
| 63 |
with gr.Row():
|
| 64 |
+
|
| 65 |
+
# --- LEFT PANEL: THE WORKFLOW CONTROLS ---
|
| 66 |
+
with gr.Column(scale=4):
|
| 67 |
|
| 68 |
+
with gr.Group():
|
| 69 |
+
gr.Markdown("### 1. Photo Ingestion")
|
| 70 |
+
img_in = gr.Image(type="filepath", label="Customer Photo", height=250)
|
| 71 |
+
|
| 72 |
+
with gr.Row():
|
| 73 |
+
use_enh_in = gr.Checkbox(value=True, label="Auto-Enhance (SSLE)")
|
| 74 |
+
btn_enhance = gr.Button("β¨ Test Enhancement", size="sm")
|
| 75 |
+
|
| 76 |
+
with gr.Group():
|
| 77 |
+
gr.Markdown("### 2. Geometry & Shape")
|
| 78 |
+
product_in = gr.Dropdown(choices=list(PRODUCTS.keys()), value="block_50x50x80_portrait", label="Target SKU")
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
shape_mask_in = gr.Dropdown(choices=["None", "Round", "Square", "Heart", "Star"], value="None", label="Shape Mask")
|
| 82 |
+
diorama_in = gr.Checkbox(value=True, label="Diorama Box Effect")
|
| 83 |
+
|
| 84 |
+
with gr.Accordion("π Framing Offsets", open=False):
|
| 85 |
+
mask_scale_in = gr.Slider(minimum=0.2, maximum=2.0, value=1.0, step=0.05, label="Mask Size (Scale)")
|
| 86 |
+
mask_x_in = gr.Slider(minimum=-50, maximum=50, value=0, step=1, label="Left/Right Offset (%)")
|
| 87 |
+
mask_y_in = gr.Slider(minimum=-50, maximum=50, value=0, step=1, label="Up/Down Offset (%)")
|
| 88 |
+
|
| 89 |
+
with gr.Group():
|
| 90 |
+
gr.Markdown("### 3. Laser Tuning")
|
| 91 |
+
with gr.Row():
|
| 92 |
+
detail_boost_in = gr.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Face Sharpness")
|
| 93 |
+
depth_vol_in = gr.Slider(minimum=0.1, maximum=0.9, value=0.65, step=0.05, label="3D Volume Depth")
|
| 94 |
+
|
| 95 |
+
with gr.Accordion("βοΈ Advanced Engine Variables", open=False):
|
| 96 |
+
with gr.Row():
|
| 97 |
+
quality_in = gr.Dropdown(choices=list(QUALITIES.keys()), value="balanced", label="Point Density")
|
| 98 |
+
face_mode_in = gr.Dropdown(choices=["single", "couple", "group"], value="single", label="Subject Type")
|
| 99 |
+
with gr.Row():
|
| 100 |
+
bg_mode_in = gr.Dropdown(choices=["remove", "off"], value="remove", label="Background Mode")
|
| 101 |
+
fp16_in = gr.Checkbox(value=True, label="GPU Acceleration")
|
| 102 |
+
|
| 103 |
+
btn_gen = gr.Button("π₯ GENERATE PRODUCTION FILE", variant="primary", size="lg")
|
| 104 |
|
| 105 |
+
# --- RIGHT PANEL: VISUAL DASHBOARD ---
|
| 106 |
+
with gr.Column(scale=5):
|
|
|
|
| 107 |
|
| 108 |
+
gr.Markdown("### ποΈ Inspection Dashboard")
|
| 109 |
|
| 110 |
+
with gr.Tabs():
|
| 111 |
+
with gr.TabItem("1. 3D Model Verification"):
|
| 112 |
+
model_out = gr.Model3D(label="Interactive 3D Preview", clear_color=[0, 0, 0, 0], height=400)
|
| 113 |
+
file_out = gr.File(label="Download for xTool Creative Space")
|
| 114 |
+
|
| 115 |
+
with gr.TabItem("2. Diagnostics (2D)"):
|
| 116 |
+
with gr.Row():
|
| 117 |
+
depth_out = gr.Image(type="filepath", label="Depth Map", interactive=False)
|
| 118 |
+
weight_out = gr.Image(type="filepath", label="Thermal Importance Map", interactive=False)
|
| 119 |
+
|
| 120 |
+
with gr.TabItem("3. Enhancement Check"):
|
| 121 |
+
enh_out = gr.Image(type="filepath", label="SSLE Output", interactive=False)
|
| 122 |
|
| 123 |
+
gr.Markdown("### π Status Log")
|
| 124 |
+
log_out = gr.Textbox(label="Engine Console", lines=3, interactive=False, show_label=False)
|
|
|
|
| 125 |
|
| 126 |
+
# --- WIRING & LOGIC ---
|
| 127 |
+
btn_enhance.click(fn=run_enhance, inputs=[img_in], outputs=[enh_out, log_out])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
btn_gen.click(
|
| 130 |
fn=run_engine,
|
| 131 |
+
inputs=[
|
| 132 |
+
img_in, product_in, face_mode_in, bg_mode_in, shape_mask_in,
|
| 133 |
+
mask_scale_in, mask_x_in, mask_y_in, diorama_in, quality_in,
|
| 134 |
+
use_enh_in, fp16_in, detail_boost_in, depth_vol_in
|
| 135 |
+
],
|
| 136 |
+
outputs=[log_out, file_out, model_out, depth_out, weight_out]
|
| 137 |
)
|
| 138 |
|
| 139 |
if __name__ == "__main__":
|
| 140 |
+
try:
|
| 141 |
+
app.launch(delete_cache=(60, 60))
|
| 142 |
+
except TypeError:
|
| 143 |
+
app.launch()
|