shiue2000 commited on
Commit
dfdbf6b
·
verified ·
1 Parent(s): 3624057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -42,9 +42,11 @@ def apply_filters(image, mode):
42
  img_color = cv2.resize(img_color, (img.shape[1], img.shape[0]))
43
  img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
44
  img_blur = cv2.medianBlur(img_gray, 7)
45
- edges = cv2.adaptiveThreshold(img_blur, 255,
46
- cv2.ADAPTIVE_THRESH_MEAN_C,
47
- cv2.THRESH_BINARY, 9, 2)
 
 
48
  edges = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
49
  cartoon = cv2.bitwise_and(img_color, edges)
50
  processed = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)
@@ -70,13 +72,14 @@ def apply_filters(image, mode):
70
  processed = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
71
 
72
  else:
73
- processed = img
74
 
75
  # Save processed image to Desktop/image/
76
  output_filename = f"{uuid.uuid4().hex}_{mode.replace(' ', '_')}.png"
77
  output_path = os.path.join(desktop_dir, output_filename)
78
  Image.fromarray(processed).save(output_path)
79
 
 
80
  return processed, output_path
81
 
82
  title = "🎨 Image Filter Lab"
@@ -98,12 +101,11 @@ demo = gr.Interface(
98
  ],
99
  outputs=[
100
  gr.Image(type="numpy", label="Filtered Image"),
101
- gr.File(label="⬇️ Download Image")
102
  ],
103
  title=title,
104
  description=description,
105
- allow_flagging="never",
106
- theme="soft"
107
  )
108
 
109
  if __name__ == "__main__":
 
42
  img_color = cv2.resize(img_color, (img.shape[1], img.shape[0]))
43
  img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
44
  img_blur = cv2.medianBlur(img_gray, 7)
45
+ edges = cv2.adaptiveThreshold(
46
+ img_blur, 255,
47
+ cv2.ADAPTIVE_THRESH_MEAN_C,
48
+ cv2.THRESH_BINARY, 9, 2
49
+ )
50
  edges = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
51
  cartoon = cv2.bitwise_and(img_color, edges)
52
  processed = cv2.cvtColor(cartoon, cv2.COLOR_BGR2RGB)
 
72
  processed = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
73
 
74
  else:
75
+ processed = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
76
 
77
  # Save processed image to Desktop/image/
78
  output_filename = f"{uuid.uuid4().hex}_{mode.replace(' ', '_')}.png"
79
  output_path = os.path.join(desktop_dir, output_filename)
80
  Image.fromarray(processed).save(output_path)
81
 
82
+ # Return numpy array for display, and file path for download
83
  return processed, output_path
84
 
85
  title = "🎨 Image Filter Lab"
 
101
  ],
102
  outputs=[
103
  gr.Image(type="numpy", label="Filtered Image"),
104
+ gr.File(label="⬇️ Download Processed Image")
105
  ],
106
  title=title,
107
  description=description,
108
+ allow_flagging="never"
 
109
  )
110
 
111
  if __name__ == "__main__":