sunbal7 commited on
Commit
776b44f
ยท
verified ยท
1 Parent(s): 3712d99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +192 -107
app.py CHANGED
@@ -6,7 +6,7 @@ from PIL import Image, ImageDraw
6
  import time
7
  import io
8
 
9
- class WorkingAirDrawingApp:
10
  def __init__(self):
11
  self.setup_page()
12
  self.setup_mediapipe()
@@ -43,76 +43,95 @@ class WorkingAirDrawingApp:
43
  border-radius: 10px;
44
  text-align: center;
45
  margin: 10px 0;
 
 
 
 
 
 
 
 
46
  }
47
  </style>
48
  """, unsafe_allow_html=True)
49
 
50
- st.markdown('<h1 class="main-title">โœจ Air Drawing Canvas</h1>', unsafe_allow_html=True)
51
- st.markdown("### Draw in air with your finger - Watch it appear on screen!")
52
 
53
  def setup_mediapipe(self):
54
  self.mp_hands = mp.solutions.hands
55
  self.mp_drawing = mp.solutions.drawing_utils
 
 
 
56
  self.hands = self.mp_hands.Hands(
57
- static_image_mode=False,
58
  max_num_hands=1,
59
- min_detection_confidence=0.7,
60
- min_tracking_confidence=0.5
 
61
  )
62
 
63
  def initialize_canvas(self):
64
  """Initialize canvas and session state"""
65
  if 'canvas' not in st.session_state:
66
- st.session_state.canvas = Image.new('RGB', (600, 400), 'white')
67
  st.session_state.draw = ImageDraw.Draw(st.session_state.canvas)
68
 
69
  if 'last_point' not in st.session_state:
70
  st.session_state.last_point = None
71
 
72
  if 'current_color' not in st.session_state:
73
- st.session_state.current_color = (255, 0, 0)
74
 
75
  if 'brush_size' not in st.session_state:
76
- st.session_state.brush_size = 8
77
 
78
  if 'is_drawing' not in st.session_state:
79
  st.session_state.is_drawing = False
 
 
 
80
 
81
- def detect_index_finger_tip(self, landmarks, frame_shape):
82
- """Detect index finger tip position"""
83
- h, w = frame_shape[:2]
84
-
85
- # Get index finger tip landmark
86
- index_tip = landmarks.landmark[self.mp_hands.HandLandmark.INDEX_FINGER_TIP]
87
 
88
- # Convert to pixel coordinates
89
- x = int(index_tip.x * w)
90
- y = int(index_tip.y * h)
91
-
92
- return (x, y)
 
 
 
 
93
 
94
- def is_index_finger_extended(self, landmarks):
95
- """Check if only index finger is extended (pointing gesture)"""
96
- # Get finger landmarks
97
- index_tip = landmarks.landmark[self.mp_hands.HandLandmark.INDEX_FINGER_TIP]
98
- middle_tip = landmarks.landmark[self.mp_hands.HandLandmark.MIDDLE_FINGER_TIP]
99
- ring_tip = landmarks.landmark[self.mp_hands.HandLandmark.RING_FINGER_TIP]
100
- pinky_tip = landmarks.landmark[self.mp_hands.HandLandmark.PINKY_TIP]
101
-
102
- # Get PIP joints
103
- index_pip = landmarks.landmark[self.mp_hands.HandLandmark.INDEX_FINGER_PIP]
104
- middle_pip = landmarks.landmark[self.mp_hands.HandLandmark.MIDDLE_FINGER_PIP]
105
- ring_pip = landmarks.landmark[self.mp_hands.HandLandmark.RING_FINGER_PIP]
106
- pinky_pip = landmarks.landmark[self.mp_hands.HandLandmark.PINKY_PIP]
107
-
108
- # Check if fingers are extended (tip is above PIP joint)
109
- index_extended = index_tip.y < index_pip.y
110
- middle_extended = middle_tip.y < middle_pip.y
111
- ring_extended = ring_tip.y < ring_pip.y
112
- pinky_extended = pinky_tip.y < pinky_pip.y
113
-
114
- # Only index finger should be extended for drawing
115
- return index_extended and not middle_extended and not ring_extended and not pinky_extended
 
 
 
116
 
117
  def update_canvas(self, finger_tip, frame_shape):
118
  """Update canvas with finger movement"""
@@ -120,106 +139,151 @@ class WorkingAirDrawingApp:
120
  return
121
 
122
  # Scale coordinates from camera to canvas
123
- canvas_x = int(finger_tip[0] * 600 / frame_shape[1])
124
- canvas_y = int(finger_tip[1] * 400 / frame_shape[0])
125
  current_point = (canvas_x, canvas_y)
126
 
127
- # Draw if we have a previous point
128
  if st.session_state.last_point and st.session_state.is_drawing:
129
  st.session_state.draw.line(
130
  [st.session_state.last_point, current_point],
131
  fill=st.session_state.current_color,
132
- width=st.session_state.brush_size
 
133
  )
134
 
135
  st.session_state.last_point = current_point
136
 
137
  def clear_canvas(self):
138
  """Clear the canvas"""
139
- st.session_state.canvas = Image.new('RGB', (600, 400), 'white')
140
  st.session_state.draw = ImageDraw.Draw(st.session_state.canvas)
141
  st.session_state.last_point = None
142
  st.session_state.is_drawing = False
 
143
 
144
  def process_frame(self, frame):
145
- """Process frame for hand detection and drawing"""
146
  # Convert BGR to RGB for MediaPipe
147
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 
 
 
 
 
148
  results = self.hands.process(rgb_frame)
149
 
150
  finger_tip = None
151
  status = "๐Ÿ‘‹ Show your hand to camera"
152
- drawing_mode = False
 
153
 
154
  if results.multi_hand_landmarks:
155
  for hand_landmarks in results.multi_hand_landmarks:
156
- # Draw hand landmarks
157
  self.mp_drawing.draw_landmarks(
158
  frame,
159
  hand_landmarks,
160
- self.mp_hands.HAND_CONNECTIONS
 
 
161
  )
162
 
163
- # Check if index finger is pointing
164
- if self.is_index_finger_extended(hand_landmarks):
165
- drawing_mode = True
166
- finger_tip = self.detect_index_finger_tip(hand_landmarks, frame.shape)
167
- status = "๐ŸŽจ DRAWING - Move your finger!"
 
 
 
 
 
 
 
168
 
169
- # Draw circle on finger tip
170
- cv2.circle(frame, finger_tip, 10, (0, 255, 0), -1)
171
  else:
172
- drawing_mode = False
173
  status = "๐Ÿ‘‰ Point with index finger to draw"
174
-
175
- return frame, drawing_mode, finger_tip, status
 
 
 
 
176
 
177
  def run(self):
178
  # Sidebar
179
  st.sidebar.title("๐ŸŽฎ Controls")
180
 
181
  st.sidebar.markdown("""
182
- ### How to Draw:
183
- 1. **Show hand** to camera
184
- 2. **Point index finger** - Green dot appears
185
- 3. **Move finger** in air - Drawing appears!
186
- 4. **Change colors/sizes** below
 
 
 
 
 
 
187
  """)
188
 
189
  # Color selection
190
  st.sidebar.subheader("๐ŸŽจ Colors")
191
  colors = {
192
- "Red": (255, 0, 0),
193
- "Blue": (0, 0, 255),
194
- "Green": (0, 255, 0),
195
- "Purple": (128, 0, 128),
196
- "Black": (0, 0, 0)
 
197
  }
198
 
199
  selected_color = st.sidebar.selectbox("Choose color:", list(colors.keys()))
200
  st.session_state.current_color = colors[selected_color]
201
 
202
  # Brush size
203
- st.sidebar.subheader("๐Ÿ–Œ๏ธ Brush")
204
- st.session_state.brush_size = st.sidebar.slider("Size:", 1, 20, 8)
205
 
206
  # Control buttons
207
  st.sidebar.subheader("โšก Actions")
208
- if st.sidebar.button("๐Ÿ—‘๏ธ Clear Canvas", use_container_width=True):
209
- self.clear_canvas()
210
- st.rerun()
211
-
212
- if st.sidebar.button("๐Ÿ’พ Save Drawing", use_container_width=True):
213
- self.save_drawing()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
- # Main content - Two columns
216
  col1, col2 = st.columns(2)
217
 
218
  with col1:
219
  st.subheader("๐Ÿ“น Camera View")
 
220
  st.markdown('<div class="container">', unsafe_allow_html=True)
221
 
222
- camera_image = st.camera_input("Start drawing...", key="camera")
223
 
224
  if camera_image:
225
  # Convert to OpenCV
@@ -227,69 +291,90 @@ class WorkingAirDrawingApp:
227
  frame = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
228
 
229
  # Process frame
230
- processed_frame, drawing_mode, finger_tip, status = self.process_frame(frame)
231
 
232
- # Update drawing state
233
- st.session_state.is_drawing = drawing_mode
 
234
 
235
- # Update canvas if drawing
236
- if drawing_mode and finger_tip:
237
- self.update_canvas(finger_tip, frame.shape)
238
  else:
239
- st.session_state.last_point = None
240
 
241
- # Add status to frame
242
- cv2.putText(processed_frame, status, (10, 30),
 
 
 
 
243
  cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
244
- cv2.putText(processed_frame, f"Brush: {st.session_state.brush_size}px", (10, 60),
245
- cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
246
 
247
  # Display frame
248
  display_frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
249
  st.image(display_frame, use_container_width=True)
250
 
 
 
 
 
251
  st.markdown('</div>', unsafe_allow_html=True)
252
 
253
- # Status
254
  if camera_image:
255
  st.markdown(f'<div class="status-box">{status}</div>', unsafe_allow_html=True)
256
- else:
257
- st.info("๐Ÿ‘† Click the camera to start!")
258
 
259
  with col2:
260
  st.subheader("๐ŸŽจ Drawing Canvas")
 
261
  st.markdown('<div class="container">', unsafe_allow_html=True)
262
 
263
  # Display canvas
264
  st.image(st.session_state.canvas, use_container_width=True,
265
- caption="Your drawing appears here!")
266
 
267
  st.markdown('</div>', unsafe_allow_html=True)
268
 
269
- # Info
270
- st.write(f"**Color:** {selected_color}")
271
- st.write(f"**Brush Size:** {st.session_state.brush_size}px")
272
- st.write(f"**Status:** {'Drawing' if st.session_state.is_drawing else 'Waiting'}")
273
-
 
 
 
 
 
 
 
 
 
 
 
 
274
  def save_drawing(self):
275
- """Save the drawing"""
276
- timestamp = str(int(time.time()))
277
- filename = f"drawing_{timestamp}.png"
278
 
279
- # Convert to bytes for download
280
  img_buffer = io.BytesIO()
281
  st.session_state.canvas.save(img_buffer, format='PNG')
282
 
 
283
  st.sidebar.download_button(
284
- label="๐Ÿ“ฅ Download Drawing",
285
  data=img_buffer.getvalue(),
286
  file_name=filename,
287
  mime="image/png",
288
  use_container_width=True
289
  )
 
 
290
 
291
  def main():
292
- app = WorkingAirDrawingApp()
293
  app.run()
294
 
295
  if __name__ == "__main__":
 
6
  import time
7
  import io
8
 
9
+ class FixedAirDrawingApp:
10
  def __init__(self):
11
  self.setup_page()
12
  self.setup_mediapipe()
 
43
  border-radius: 10px;
44
  text-align: center;
45
  margin: 10px 0;
46
+ font-weight: bold;
47
+ }
48
+ .debug-info {
49
+ background: #FF6B6B;
50
+ color: white;
51
+ padding: 10px;
52
+ border-radius: 5px;
53
+ font-family: monospace;
54
  }
55
  </style>
56
  """, unsafe_allow_html=True)
57
 
58
+ st.markdown('<h1 class="main-title">โœจ Air Drawing Canvas - FIXED</h1>', unsafe_allow_html=True)
59
+ st.markdown("### Point with index finger - Green dot WILL appear! ๐ŸŽฏ")
60
 
61
  def setup_mediapipe(self):
62
  self.mp_hands = mp.solutions.hands
63
  self.mp_drawing = mp.solutions.drawing_utils
64
+ self.mp_drawing_styles = mp.solutions.drawing_styles
65
+
66
+ # Enhanced hand detection with better parameters
67
  self.hands = self.mp_hands.Hands(
68
+ static_image_mode=False, # Changed to False for video
69
  max_num_hands=1,
70
+ model_complexity=1, # Added for better accuracy
71
+ min_detection_confidence=0.5, # Lowered threshold
72
+ min_tracking_confidence=0.5 # Lowered threshold
73
  )
74
 
75
  def initialize_canvas(self):
76
  """Initialize canvas and session state"""
77
  if 'canvas' not in st.session_state:
78
+ st.session_state.canvas = Image.new('RGB', (800, 600), 'white')
79
  st.session_state.draw = ImageDraw.Draw(st.session_state.canvas)
80
 
81
  if 'last_point' not in st.session_state:
82
  st.session_state.last_point = None
83
 
84
  if 'current_color' not in st.session_state:
85
+ st.session_state.current_color = (255, 0, 0) # Red
86
 
87
  if 'brush_size' not in st.session_state:
88
+ st.session_state.brush_size = 10
89
 
90
  if 'is_drawing' not in st.session_state:
91
  st.session_state.is_drawing = False
92
+
93
+ if 'debug_info' not in st.session_state:
94
+ st.session_state.debug_info = "Waiting for camera..."
95
 
96
+ def get_finger_tip(self, landmarks, frame_shape):
97
+ """Get index finger tip position with better detection"""
98
+ h, w, c = frame_shape
 
 
 
99
 
100
+ try:
101
+ # Get index finger tip (landmark 8)
102
+ index_tip = landmarks.landmark[8]
103
+ x = int(index_tip.x * w)
104
+ y = int(index_tip.y * h)
105
+
106
+ return (x, y)
107
+ except:
108
+ return None
109
 
110
+ def is_pointing_gesture(self, landmarks):
111
+ """Check if hand is making a pointing gesture"""
112
+ try:
113
+ # Get relevant landmarks
114
+ index_tip = landmarks.landmark[8]
115
+ middle_tip = landmarks.landmark[12]
116
+ ring_tip = landmarks.landmark[16]
117
+ pinky_tip = landmarks.landmark[20]
118
+
119
+ # Get PIP joints (second knuckles)
120
+ index_pip = landmarks.landmark[6]
121
+ middle_pip = landmarks.landmark[10]
122
+ ring_pip = landmarks.landmark[14]
123
+ pinky_pip = landmarks.landmark[18]
124
+
125
+ # Check if index finger is extended and others are folded
126
+ index_extended = index_tip.y < index_pip.y # Tip above PIP
127
+ middle_folded = middle_tip.y > middle_pip.y # Tip below PIP
128
+ ring_folded = ring_tip.y > ring_pip.y
129
+ pinky_folded = pinky_tip.y > pinky_pip.y
130
+
131
+ return index_extended and middle_folded and ring_folded and pinky_folded
132
+
133
+ except Exception as e:
134
+ return False
135
 
136
  def update_canvas(self, finger_tip, frame_shape):
137
  """Update canvas with finger movement"""
 
139
  return
140
 
141
  # Scale coordinates from camera to canvas
142
+ canvas_x = int(finger_tip[0] * 800 / frame_shape[1])
143
+ canvas_y = int(finger_tip[1] * 600 / frame_shape[0])
144
  current_point = (canvas_x, canvas_y)
145
 
146
+ # Draw line from last point to current point
147
  if st.session_state.last_point and st.session_state.is_drawing:
148
  st.session_state.draw.line(
149
  [st.session_state.last_point, current_point],
150
  fill=st.session_state.current_color,
151
+ width=st.session_state.brush_size,
152
+ joint="curve"
153
  )
154
 
155
  st.session_state.last_point = current_point
156
 
157
  def clear_canvas(self):
158
  """Clear the canvas"""
159
+ st.session_state.canvas = Image.new('RGB', (800, 600), 'white')
160
  st.session_state.draw = ImageDraw.Draw(st.session_state.canvas)
161
  st.session_state.last_point = None
162
  st.session_state.is_drawing = False
163
+ st.session_state.debug_info = "Canvas cleared!"
164
 
165
  def process_frame(self, frame):
166
+ """Process frame for hand detection with enhanced visualization"""
167
  # Convert BGR to RGB for MediaPipe
168
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
169
+
170
+ # Flip frame horizontally for mirror effect
171
+ rgb_frame = cv2.flip(rgb_frame, 1)
172
+ frame = cv2.flip(frame, 1)
173
+
174
  results = self.hands.process(rgb_frame)
175
 
176
  finger_tip = None
177
  status = "๐Ÿ‘‹ Show your hand to camera"
178
+ is_pointing = False
179
+ debug_info = "No hand detected"
180
 
181
  if results.multi_hand_landmarks:
182
  for hand_landmarks in results.multi_hand_landmarks:
183
+ # Draw ALL hand landmarks (for debugging)
184
  self.mp_drawing.draw_landmarks(
185
  frame,
186
  hand_landmarks,
187
+ self.mp_hands.HAND_CONNECTIONS,
188
+ self.mp_drawing_styles.get_default_hand_landmarks_style(),
189
+ self.mp_drawing_styles.get_default_hand_connections_style()
190
  )
191
 
192
+ # Check if pointing gesture
193
+ is_pointing = self.is_pointing_gesture(hand_landmarks)
194
+ finger_tip = self.get_finger_tip(hand_landmarks, frame.shape)
195
+
196
+ if is_pointing and finger_tip:
197
+ status = "๐ŸŽจ DRAWING MODE - Move your finger!"
198
+ debug_info = f"Pointing! Finger at: {finger_tip}"
199
+
200
+ # Draw LARGE green dot on finger tip
201
+ cv2.circle(frame, finger_tip, 15, (0, 255, 0), -1) # Green fill
202
+ cv2.circle(frame, finger_tip, 8, (255, 255, 255), -1) # White inner
203
+ cv2.circle(frame, finger_tip, 20, (0, 255, 0), 2) # Green outline
204
 
 
 
205
  else:
 
206
  status = "๐Ÿ‘‰ Point with index finger to draw"
207
+ debug_info = "Hand detected but not pointing"
208
+
209
+ else:
210
+ debug_info = "No hand landmarks detected - try moving closer"
211
+
212
+ return frame, is_pointing, finger_tip, status, debug_info
213
 
214
  def run(self):
215
  # Sidebar
216
  st.sidebar.title("๐ŸŽฎ Controls")
217
 
218
  st.sidebar.markdown("""
219
+ ### ๐ŸŽฏ How to Make it Work:
220
+ 1. **Good lighting** - Face a light source
221
+ 2. **Show entire hand** - Palm facing camera
222
+ 3. **Point index finger** - Keep other fingers folded
223
+ 4. **Move slowly** - Smooth movements work better
224
+ 5. **Stay close** - 1-2 feet from camera
225
+
226
+ ### โœจ Gesture:
227
+ - **Index finger extended**
228
+ - **Other fingers folded**
229
+ - **Palm facing camera**
230
  """)
231
 
232
  # Color selection
233
  st.sidebar.subheader("๐ŸŽจ Colors")
234
  colors = {
235
+ "Red ๐Ÿ”ด": (255, 0, 0),
236
+ "Blue ๐Ÿ”ต": (0, 0, 255),
237
+ "Green ๐ŸŸข": (0, 255, 0),
238
+ "Purple ๐ŸŸฃ": (128, 0, 128),
239
+ "Black โšซ": (0, 0, 0),
240
+ "Orange ๐ŸŸ ": (255, 165, 0)
241
  }
242
 
243
  selected_color = st.sidebar.selectbox("Choose color:", list(colors.keys()))
244
  st.session_state.current_color = colors[selected_color]
245
 
246
  # Brush size
247
+ st.sidebar.subheader("๐Ÿ–Œ๏ธ Brush Settings")
248
+ st.session_state.brush_size = st.sidebar.slider("Size:", 5, 25, 12)
249
 
250
  # Control buttons
251
  st.sidebar.subheader("โšก Actions")
252
+ col1, col2 = st.sidebar.columns(2)
253
+
254
+ with col1:
255
+ if st.button("๐Ÿ—‘๏ธ Clear Canvas", use_container_width=True):
256
+ self.clear_canvas()
257
+ st.rerun()
258
+
259
+ with col_2:
260
+ if st.button("๐Ÿ”ง Test Camera", use_container_width=True):
261
+ st.session_state.debug_info = "Camera test requested..."
262
+ st.rerun()
263
+
264
+ # Debug info in sidebar
265
+ st.sidebar.subheader("๐Ÿ”ง Debug Info")
266
+ st.sidebar.code(st.session_state.debug_info)
267
+
268
+ # Quick tips
269
+ st.sidebar.subheader("๐Ÿ’ก Quick Tips")
270
+ st.sidebar.info("""
271
+ - Ensure good lighting
272
+ - Show entire hand clearly
273
+ - Point only index finger
274
+ - Keep hand steady
275
+ - Move slowly for smooth lines
276
+ """)
277
 
278
+ # Main content
279
  col1, col2 = st.columns(2)
280
 
281
  with col1:
282
  st.subheader("๐Ÿ“น Camera View")
283
+ st.markdown("**Look for the GREEN DOT on your finger tip!**")
284
  st.markdown('<div class="container">', unsafe_allow_html=True)
285
 
286
+ camera_image = st.camera_input("Start drawing...", key="main_camera")
287
 
288
  if camera_image:
289
  # Convert to OpenCV
 
291
  frame = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
292
 
293
  # Process frame
294
+ processed_frame, is_pointing, finger_tip, status, debug_info = self.process_frame(frame)
295
 
296
+ # Update session state
297
+ st.session_state.is_drawing = is_pointing
298
+ st.session_state.debug_info = debug_info
299
 
300
+ # Update canvas if pointing
301
+ if is_pointing and finger_tip:
302
+ self.update_canvas(finger_tip, processed_frame.shape)
303
  else:
304
+ st.session_state.last_point = None # Reset when not pointing
305
 
306
+ # Add status overlay
307
+ cv2.putText(processed_frame, status, (20, 40),
308
+ cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)
309
+ cv2.putText(processed_frame, f"Brush: {st.session_state.brush_size}px", (20, 80),
310
+ cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
311
+ cv2.putText(processed_frame, f"Color: {selected_color}", (20, 120),
312
  cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
 
 
313
 
314
  # Display frame
315
  display_frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
316
  st.image(display_frame, use_container_width=True)
317
 
318
+ else:
319
+ st.info("๐Ÿ‘† **Click the camera button above to start!**")
320
+ st.session_state.debug_info = "Waiting for camera input..."
321
+
322
  st.markdown('</div>', unsafe_allow_html=True)
323
 
324
+ # Status display
325
  if camera_image:
326
  st.markdown(f'<div class="status-box">{status}</div>', unsafe_allow_html=True)
 
 
327
 
328
  with col2:
329
  st.subheader("๐ŸŽจ Drawing Canvas")
330
+ st.markdown("**Your drawing will appear here!**")
331
  st.markdown('<div class="container">', unsafe_allow_html=True)
332
 
333
  # Display canvas
334
  st.image(st.session_state.canvas, use_container_width=True,
335
+ caption="โœจ Your air drawing appears here!")
336
 
337
  st.markdown('</div>', unsafe_allow_html=True)
338
 
339
+ # Drawing info
340
+ st.subheader("๐Ÿ“Š Drawing Info")
341
+ col_info1, col_info2 = st.columns(2)
342
+
343
+ with col_info1:
344
+ st.metric("Drawing Mode", "ACTIVE ๐ŸŸข" if st.session_state.is_drawing else "INACTIVE ๐Ÿ”ด")
345
+ st.metric("Brush Size", f"{st.session_state.brush_size}px")
346
+
347
+ with col_info2:
348
+ st.metric("Current Color", selected_color)
349
+ st.metric("Canvas Size", "800ร—600")
350
+
351
+ # Save functionality
352
+ st.subheader("๐Ÿ’พ Save Drawing")
353
+ if st.button("๐Ÿ’ซ Download Masterpiece", use_container_width=True):
354
+ self.save_drawing()
355
+
356
  def save_drawing(self):
357
+ """Save the drawing as downloadable file"""
358
+ timestamp = time.strftime("%Y%m%d_%H%M%S")
359
+ filename = f"air_drawing_{timestamp}.png"
360
 
361
+ # Convert canvas to bytes
362
  img_buffer = io.BytesIO()
363
  st.session_state.canvas.save(img_buffer, format='PNG')
364
 
365
+ # Create download button
366
  st.sidebar.download_button(
367
+ label="๐Ÿ“ฅ Download Your Drawing",
368
  data=img_buffer.getvalue(),
369
  file_name=filename,
370
  mime="image/png",
371
  use_container_width=True
372
  )
373
+
374
+ st.sidebar.success(f"โœ… Ready to download: {filename}")
375
 
376
  def main():
377
+ app = FixedAirDrawingApp()
378
  app.run()
379
 
380
  if __name__ == "__main__":