Mahmoudmody777 commited on
Commit
4bcc9a6
·
verified ·
1 Parent(s): 4f59031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -27
app.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image, ImageOps, ImageEnhance
5
  import subprocess
6
  import os
7
 
8
- # --- CNC BRAIN V8: SMOOTH MASTER (Detail + Curves Balanced) ---
9
  def process_vector(image, invert_input, contrast_boost, detail_threshold, solid_force, smooth_factor):
10
  if image is None: return None, None
11
 
@@ -29,8 +29,6 @@ def process_vector(image, invert_input, contrast_boost, detail_threshold, solid_
29
 
30
  # --- SOLID FORCE & CLEANING ---
31
  kernel = np.ones((3,3), np.uint8)
32
-
33
- # Noise cleaning
34
  binary = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel, iterations=1)
35
 
36
  if solid_force > 0:
@@ -42,10 +40,9 @@ def process_vector(image, invert_input, contrast_boost, detail_threshold, solid_
42
  # Save Temp
43
  temp_bmp = "temp_trace.bmp"
44
  output_svg = "ts_vector_smooth.svg"
45
-
46
  cv2.imwrite(temp_bmp, final_binary)
47
 
48
- # --- VECTORIZE WITH SMOOTHING ENGINE ---
49
  cmd = [
50
  "potrace", temp_bmp,
51
  "-s", "-o", output_svg,
@@ -71,11 +68,10 @@ body, .gradio-container { font-family: 'Inter', sans-serif !important; backgroun
71
  .primary-btn { background: linear-gradient(45deg, #00b8ff, #00ff88) !important; color: black !important; font-weight: 900 !important; letter-spacing: 1px; }
72
  """
73
 
74
- # تم إزالة css و theme من هنا (لأنها انتقلت للأسفل في التحديث الجديد)
75
- with gr.Blocks() as app:
76
  with gr.Column(elem_id="main_card"):
77
  gr.Markdown("# 🌀 TS VECTOR V8 (Smooth)", elem_id="logo_text")
78
- gr.Markdown("### Perfect Curves for CNC Cutting")
79
 
80
  with gr.Row():
81
  with gr.Column():
@@ -83,33 +79,22 @@ with gr.Blocks() as app:
83
 
84
  gr.Markdown("### ⚙️ Controls")
85
  inv_chk = gr.Checkbox(label="Is Design WHITE on BLACK?", value=False)
86
-
87
- # Basic Controls
88
- cont_sld = gr.Slider(1.0, 2.5, value=1.5, step=0.1, label="1. Contrast (Detail Ubharo)")
89
- thresh_sld = gr.Slider(0, 255, value=170, step=1, label="2. Detail Cutoff (Preview dekho)")
90
- solid_sld = gr.Slider(0, 3, value=0, step=1, label="3. Solid Force (Mota karne ke liye)")
91
-
92
- # --- NEW SMOOTH SLIDER ---
93
- gr.Markdown("### 🌀 Curve Control (Golai)")
94
- smooth_sld = gr.Slider(0.0, 1.34, value=1.0, step=0.1, label="4. Smoothing Factor (0=Kata hua, 1.0=Mast Golai)")
95
 
96
  btn = gr.Button("⚡ CREATE SMOOTH VECTOR", variant="primary", elem_classes=["primary-btn"])
97
 
98
  with gr.Column():
99
- preview_img = gr.Image(label="Computer Vision Preview (Black = Cut)", interactive=False)
100
  out_file = gr.File(label="Download SVG")
101
 
 
102
  btn.click(process_vector,
103
  inputs=[inp_img, inv_chk, cont_sld, thresh_sld, solid_sld, smooth_sld],
104
  outputs=[out_file, preview_img],
105
  api_name="predict")
106
 
107
- # التعديل الهام هنا:
108
- # 1. نقل css و theme إلى داخل launch (لحل التحذير)
109
- # 2. تغيير cors_allowed_origins إلى allowed_origins (لحل الخطأ)
110
- # 3. وضع النجمة داخل قائمة ["*"]
111
- app.launch(
112
- theme=gr.themes.Soft(),
113
- css=custom_css,
114
- allowed_origins=["*"]
115
- )
 
5
  import subprocess
6
  import os
7
 
8
+ # --- CNC BRAIN V8: SMOOTH MASTER ---
9
  def process_vector(image, invert_input, contrast_boost, detail_threshold, solid_force, smooth_factor):
10
  if image is None: return None, None
11
 
 
29
 
30
  # --- SOLID FORCE & CLEANING ---
31
  kernel = np.ones((3,3), np.uint8)
 
 
32
  binary = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel, iterations=1)
33
 
34
  if solid_force > 0:
 
40
  # Save Temp
41
  temp_bmp = "temp_trace.bmp"
42
  output_svg = "ts_vector_smooth.svg"
 
43
  cv2.imwrite(temp_bmp, final_binary)
44
 
45
+ # --- VECTORIZE ---
46
  cmd = [
47
  "potrace", temp_bmp,
48
  "-s", "-o", output_svg,
 
68
  .primary-btn { background: linear-gradient(45deg, #00b8ff, #00ff88) !important; color: black !important; font-weight: 900 !important; letter-spacing: 1px; }
69
  """
70
 
71
+ # هنا عدنا للطريقة الكلاسيكية المضمونة التي لا تسبب أخطاء
72
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as app:
73
  with gr.Column(elem_id="main_card"):
74
  gr.Markdown("# 🌀 TS VECTOR V8 (Smooth)", elem_id="logo_text")
 
75
 
76
  with gr.Row():
77
  with gr.Column():
 
79
 
80
  gr.Markdown("### ⚙️ Controls")
81
  inv_chk = gr.Checkbox(label="Is Design WHITE on BLACK?", value=False)
82
+ cont_sld = gr.Slider(1.0, 2.5, value=1.5, step=0.1, label="1. Contrast")
83
+ thresh_sld = gr.Slider(0, 255, value=170, step=1, label="2. Detail Cutoff")
84
+ solid_sld = gr.Slider(0, 3, value=0, step=1, label="3. Solid Force")
85
+ smooth_sld = gr.Slider(0.0, 1.34, value=1.0, step=0.1, label="4. Smoothing Factor")
 
 
 
 
 
86
 
87
  btn = gr.Button("⚡ CREATE SMOOTH VECTOR", variant="primary", elem_classes=["primary-btn"])
88
 
89
  with gr.Column():
90
+ preview_img = gr.Image(label="Preview", interactive=False)
91
  out_file = gr.File(label="Download SVG")
92
 
93
+ # هذا هو المهم للربط الخارجي
94
  btn.click(process_vector,
95
  inputs=[inp_img, inv_chk, cont_sld, thresh_sld, solid_sld, smooth_sld],
96
  outputs=[out_file, preview_img],
97
  api_name="predict")
98
 
99
+ # إطلاق التطبيق بدون وسائط إضافية تسبب مشاكل
100
+ app.launch()