sunbal7 commited on
Commit
ff0153c
·
verified ·
1 Parent(s): b659f77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +232 -305
app.py CHANGED
@@ -1,365 +1,292 @@
1
  import streamlit as st
2
  import cv2
3
  import numpy as np
4
- from PIL import Image, ImageDraw, ImageFont
5
- import requests
6
- import tempfile
7
- import os
8
- from pathlib import Path
9
 
10
- class MemeYourselfApp:
11
  def __init__(self):
12
  self.setup_page()
13
- self.meme_templates = self.load_meme_templates()
 
14
 
15
  def setup_page(self):
16
  st.set_page_config(
17
- page_title="Meme Yourself 🎭",
18
- page_icon="😂",
19
- layout="wide",
20
- initial_sidebar_state="expanded"
21
  )
22
 
23
- # Custom CSS for better styling
24
  st.markdown("""
25
  <style>
26
- .main-header {
27
- font-size: 3rem;
28
- color: #FF6B6B;
 
 
29
  text-align: center;
30
- margin-bottom: 2rem;
31
  font-weight: bold;
32
- text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
33
  }
34
- .meme-container {
35
  border: 3px solid #4ECDC4;
36
  border-radius: 15px;
37
- padding: 20px;
38
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
39
- margin: 10px 0;
40
  }
41
- .stButton button {
42
- background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
43
  color: white;
44
- border: none;
45
- padding: 12px 24px;
46
- border-radius: 25px;
47
- font-weight: bold;
48
- transition: all 0.3s ease;
49
- }
50
- .stButton button:hover {
51
- transform: scale(1.05);
52
- box-shadow: 0 5px 15px rgba(0,0,0,0.3);
53
  }
54
  </style>
55
  """, unsafe_allow_html=True)
56
 
57
- st.markdown('<h1 class="main-header">🎭 Meme Yourself</h1>', unsafe_allow_html=True)
58
- st.markdown("### Turn your facial expressions into instant memes! 😂")
59
 
60
- def load_meme_templates(self):
61
- """Define meme templates with their configurations"""
62
- templates = {
63
- "angry": {
64
- "name": "Change My Mind",
65
- "text": "This is the best meme app\n*Change My Mind*",
66
- "text_position": (50, 400),
67
- "text_color": "white",
68
- "font_size": 40,
69
- "face_position": (300, 150),
70
- "face_size": (200, 200)
71
- },
72
- "surprised": {
73
- "name": "Surprised Pikachu",
74
- "text": "When you realize\nhow awesome this app is",
75
- "text_position": (50, 450),
76
- "text_color": "black",
77
- "font_size": 35,
78
- "face_position": (250, 100),
79
- "face_size": (250, 250)
80
- },
81
- "happy": {
82
- "name": "Success Kid",
83
- "text": "Made a viral meme\nWent famous on social media",
84
- "text_position": (50, 50),
85
- "text_color": "white",
86
- "font_size": 30,
87
- "face_position": (150, 200),
88
- "face_size": (180, 180)
89
- },
90
- "sad": {
91
- "name": "Sad Cat",
92
- "text": "When you have to wait\nfor the next meme",
93
- "text_position": (50, 400),
94
- "text_color": "white",
95
- "font_size": 35,
96
- "face_position": (280, 150),
97
- "face_size": (200, 200)
98
- },
99
- "neutral": {
100
- "name": "Drake Reaction",
101
- "text_top": "Other meme apps",
102
- "text_bottom": "This Meme Yourself app",
103
- "text_position_top": (200, 100),
104
- "text_position_bottom": (200, 300),
105
- "text_color": "white",
106
- "font_size": 30,
107
- "face_position": (50, 150),
108
- "face_size": (150, 150)
109
- }
110
- }
111
- return templates
112
-
113
- def create_meme_background(self, template_key):
114
- """Create colored background for memes"""
115
- background_colors = {
116
- "angry": (41, 128, 185), # Blue
117
- "surprised": (241, 196, 15), # Yellow
118
- "happy": (39, 174, 96), # Green
119
- "sad": (142, 68, 173), # Purple
120
- "neutral": (230, 126, 34) # Orange
121
- }
122
 
123
- bg_color = background_colors.get(template_key, (52, 152, 219))
124
- background = Image.new('RGB', (600, 600), bg_color)
125
- return background
126
-
127
- def detect_face_expression(self, face_image):
128
- """Simple face expression detection based on facial features"""
129
- try:
130
- # Convert to grayscale
131
- gray = cv2.cvtColor(face_image, cv2.COLOR_BGR2GRAY)
132
 
133
- # Load Haar cascades
134
- face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
135
- eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')
136
- smile_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_smile.xml')
137
 
138
- faces = face_cascade.detectMultiScale(gray, 1.3, 5)
 
139
 
140
- if len(faces) == 0:
141
- return "neutral"
142
 
143
- for (x, y, w, h) in faces:
144
- roi_gray = gray[y:y+h, x:x+w]
145
-
146
- # Detect eyes and smile
147
- eyes = eye_cascade.detectMultiScale(roi_gray, 1.1, 5)
148
- smiles = smile_cascade.detectMultiScale(roi_gray, 1.8, 20)
149
-
150
- # Simple expression logic
151
- if len(smiles) > 0:
152
- return "happy"
153
- elif len(eyes) == 0:
154
- return "surprised"
155
- elif len(eyes) >= 2 and len(smiles) == 0:
156
- return "neutral"
157
- else:
158
- return "neutral"
159
-
160
- except Exception as e:
161
- st.warning(f"Expression detection: {e}")
162
 
163
- return "neutral"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- def extract_face(self, image):
166
- """Extract face from image using OpenCV"""
167
- try:
168
- # Convert PIL to OpenCV
169
- opencv_image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
170
- gray = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2GRAY)
171
-
172
- face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
173
- faces = face_cascade.detectMultiScale(gray, 1.3, 5)
 
174
 
175
- if len(faces) > 0:
176
- x, y, w, h = faces[0]
177
- # Expand the face area a bit
178
- x = max(0, x - 20)
179
- y = max(0, y - 20)
180
- w = min(w + 40, opencv_image.shape[1] - x)
181
- h = min(h + 40, opencv_image.shape[0] - y)
182
 
183
- face = opencv_image[y:y+h, x:x+w]
184
- return Image.fromarray(cv2.cvtColor(face, cv2.COLOR_BGR2RGB))
185
-
186
- except Exception as e:
187
- st.error(f"Face extraction error: {e}")
188
-
189
- return None
190
 
191
- def add_text_to_meme(self, draw, template_config, expression):
192
- """Add text to meme based on template"""
193
- try:
194
- # Try to load a font, fallback to default
195
- try:
196
- font = ImageFont.truetype("arial.ttf", template_config["font_size"])
197
- except:
198
- font = ImageFont.load_default()
199
 
200
- if expression == "neutral":
201
- # Two lines for Drake template
202
- draw.text(template_config["text_position_top"],
203
- template_config["text_top"],
204
- fill=template_config["text_color"],
205
- font=font)
206
- draw.text(template_config["text_position_bottom"],
207
- template_config["text_bottom"],
208
- fill=template_config["text_color"],
209
- font=font)
210
- else:
211
- # Single text block
212
- lines = template_config["text"].split('\n')
213
- y_offset = template_config["text_position"][1]
214
- for line in lines:
215
- draw.text((template_config["text_position"][0], y_offset),
216
- line,
217
- fill=template_config["text_color"],
218
- font=font)
219
- y_offset += template_config["font_size"] + 5
220
-
221
- except Exception as e:
222
- st.error(f"Text rendering error: {e}")
223
 
224
- def create_meme(self, face_image, expression):
225
- """Create the final meme"""
226
- template_config = self.meme_templates.get(expression, self.meme_templates["neutral"])
 
 
 
 
 
 
 
227
 
228
- # Create background
229
- meme_img = self.create_meme_background(expression)
230
- draw = ImageDraw.Draw(meme_img)
 
 
 
 
 
231
 
232
- # Add face if available
233
- if face_image:
234
- face_resized = face_image.resize(template_config["face_size"], Image.LANCZOS)
235
- meme_img.paste(face_resized, template_config["face_position"])
 
 
 
 
 
 
236
 
237
- # Add text
238
- self.add_text_to_meme(draw, template_config, expression)
 
 
 
239
 
240
- return meme_img
241
-
242
- def run(self):
243
- # Sidebar
244
- st.sidebar.title("🎯 How It Works")
245
- st.sidebar.markdown("""
246
- 1. **Take a photo** with your camera
247
- 2. **AI detects your expression** automatically
248
- 3. **Choose your favorite meme template**
249
- 4. **Download and share** on social media!
250
 
251
- ### Expressions Detected:
252
- - 😠 Angry → "Change My Mind"
253
- - 😲 Surprised → "Surprised Pikachu"
254
- - 😊 Happy → "Success Kid"
255
- - 😢 Sad → "Sad Cat"
256
- - 😐 Neutral → "Drake Reaction"
257
- """)
258
 
259
- # Main content
260
- col1, col2 = st.columns([1, 1])
 
 
 
 
 
 
 
 
 
261
 
262
  with col1:
263
- st.subheader("📸 Step 1: Take Your Photo")
264
- camera_image = st.camera_input("Smile for the meme! 😊", key="main_camera")
 
 
265
 
266
  if camera_image:
267
- # Convert to PIL
268
  image = Image.open(camera_image)
 
 
269
 
270
- # Extract face
271
- with st.spinner("Detecting your expression..."):
272
- face_img = self.extract_face(image)
273
-
274
- if face_img:
275
- # Convert to OpenCV for expression detection
276
- opencv_face = cv2.cvtColor(np.array(face_img), cv2.COLOR_RGB2BGR)
277
- expression = self.detect_face_expression(opencv_face)
278
-
279
- st.success(f"Detected Expression: {expression.upper()} 😄")
280
-
281
- # Show extracted face
282
- st.image(face_img, caption="Your extracted face", use_column_width=True)
283
-
284
- # Store in session state
285
- st.session_state.face_image = face_img
286
- st.session_state.detected_expression = expression
287
- else:
288
- st.error("😞 No face detected! Please try again with better lighting.")
289
- st.session_state.face_image = None
290
-
291
- with col2:
292
- st.subheader("🎭 Step 2: Create Your Meme")
293
-
294
- if 'face_image' in st.session_state and st.session_state.face_image is not None:
295
- # Expression selection
296
- detected_exp = st.session_state.detected_expression
297
- expressions = list(self.meme_templates.keys())
298
- selected_expression = st.selectbox(
299
- "Choose meme template:",
300
- options=expressions,
301
- index=expressions.index(detected_exp) if detected_exp in expressions else 0,
302
- format_func=lambda x: f"{x.title()} - {self.meme_templates[x]['name']}"
303
- )
304
 
305
- # Create meme button
306
- if st.button("🎨 Generate Meme!", key="generate_meme"):
307
- with st.spinner("Creating your masterpiece..."):
308
- meme_result = self.create_meme(
309
- st.session_state.face_image,
310
- selected_expression
 
 
 
 
311
  )
312
 
313
- st.session_state.meme_result = meme_result
314
-
315
- # Display result
316
- if 'meme_result' in st.session_state:
317
- st.subheader("✨ Your Meme Masterpiece!")
318
- st.image(st.session_state.meme_result, use_column_width=True)
319
-
320
- # Download button
321
- buf = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
322
- st.session_state.meme_result.save(buf, format='PNG')
323
-
324
- with open(buf.name, "rb") as file:
325
- btn = st.download_button(
326
- label="📥 Download Meme",
327
- data=file,
328
- file_name="my_viral_meme.png",
329
- mime="image/png"
330
  )
331
-
332
- # Share buttons
333
- st.markdown("### 📱 Share Your Meme!")
334
- col_share1, col_share2, col_share3 = st.columns(3)
335
-
336
- with col_share1:
337
- st.button("📸 Instagram")
338
- with col_share2:
339
- st.button("🐦 Twitter")
340
- with col_share3:
341
- st.button("💬 WhatsApp")
342
-
343
- st.markdown("---")
344
- st.success("🎉 Your meme is ready to go viral! Share it with the world!")
345
-
346
- else:
347
- st.info("👆 Take a photo first to create your meme!")
 
 
 
 
 
 
348
 
349
- # Show sample memes
350
- st.subheader("🎪 Sample Memes")
351
- sample_col1, sample_col2 = st.columns(2)
 
 
 
 
352
 
353
- with sample_col1:
354
- st.image(self.create_meme_background("happy"),
355
- caption="Happy Meme Template", use_column_width=True)
356
- with sample_col2:
357
- st.image(self.create_meme_background("surprised"),
358
- caption="Surprised Meme Template", use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
 
360
  def main():
361
- # Initialize app
362
- app = MemeYourselfApp()
363
  app.run()
364
 
365
  if __name__ == "__main__":
 
1
  import streamlit as st
2
  import cv2
3
  import numpy as np
4
+ import mediapipe as mp
5
+ from PIL import Image, ImageDraw
6
+ import time
 
 
7
 
8
+ class AirDrawingCanvas:
9
  def __init__(self):
10
  self.setup_page()
11
+ self.setup_mediapipe()
12
+ self.initialize_canvas()
13
 
14
  def setup_page(self):
15
  st.set_page_config(
16
+ page_title="Magic Air Drawing 🎨",
17
+ page_icon="✨",
18
+ layout="wide"
 
19
  )
20
 
 
21
  st.markdown("""
22
  <style>
23
+ .main-title {
24
+ font-size: 3.5rem;
25
+ background: linear-gradient(45deg, #FF6B6B, #4ECDC4, #45B7D1, #96CEB4);
26
+ -webkit-background-clip: text;
27
+ -webkit-text-fill-color: transparent;
28
  text-align: center;
29
+ margin-bottom: 1rem;
30
  font-weight: bold;
 
31
  }
32
+ .canvas-container {
33
  border: 3px solid #4ECDC4;
34
  border-radius: 15px;
35
+ padding: 10px;
36
+ background: white;
37
+ box-shadow: 0 8px 25px rgba(0,0,0,0.1);
38
  }
39
+ .control-panel {
40
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
41
  color: white;
42
+ padding: 20px;
43
+ border-radius: 15px;
44
+ margin: 10px 0;
 
 
 
 
 
 
45
  }
46
  </style>
47
  """, unsafe_allow_html=True)
48
 
49
+ st.markdown('<h1 class="main-title">🎨 Magic Air Drawing Canvas</h1>', unsafe_allow_html=True)
50
+ st.markdown("### Draw in the air with your finger and watch it appear magically on the screen! ✨")
51
 
52
+ def setup_mediapipe(self):
53
+ self.mp_hands = mp.solutions.hands
54
+ self.mp_drawing = mp.solutions.drawing_utils
55
+ self.hands = self.mp_hands.Hands(
56
+ static_image_mode=False,
57
+ max_num_hands=1,
58
+ min_detection_confidence=0.7,
59
+ min_tracking_confidence=0.5
60
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
+ def initialize_canvas(self):
63
+ """Initialize the drawing canvas"""
64
+ if 'canvas' not in st.session_state:
65
+ # Create a white canvas
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 'drawing_points' not in st.session_state:
70
+ st.session_state.drawing_points = []
 
 
71
 
72
+ if 'is_drawing' not in st.session_state:
73
+ st.session_state.is_drawing = False
74
 
75
+ if 'current_color' not in st.session_state:
76
+ st.session_state.current_color = (255, 0, 0) # Red
77
 
78
+ if 'brush_size' not in st.session_state:
79
+ st.session_state.brush_size = 5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
+ def detect_drawing_gesture(self, landmarks, img_width, img_height):
82
+ """Detect if user is making a drawing gesture (index finger pointing)"""
83
+ # Get key landmarks
84
+ index_tip = landmarks[8]
85
+ middle_tip = landmarks[12]
86
+ ring_tip = landmarks[16]
87
+ pinky_tip = landmarks[20]
88
+ thumb_tip = landmarks[4]
89
+
90
+ # Convert to pixel coordinates
91
+ index_tip_px = (int(index_tip.x * img_width), int(index_tip.y * img_height))
92
+
93
+ # Check if only index finger is extended (pointing gesture)
94
+ fingers_extended = self.count_extended_fingers(landmarks, img_width, img_height)
95
+
96
+ return fingers_extended == 1, index_tip_px
97
 
98
+ def count_extended_fingers(self, landmarks, img_width, img_height):
99
+ """Count how many fingers are extended"""
100
+ finger_tips = [8, 12, 16, 20] # Index, Middle, Ring, Pinky
101
+ finger_pips = [6, 10, 14, 18] # PIP joints
102
+
103
+ extended_count = 0
104
+
105
+ for tip_idx, pip_idx in zip(finger_tips, finger_pips):
106
+ tip_y = landmarks[tip_idx].y * img_height
107
+ pip_y = landmarks[pip_idx].y * img_height
108
 
109
+ # Finger is extended if tip is above PIP joint
110
+ if tip_y < pip_y:
111
+ extended_count += 1
 
 
 
 
112
 
113
+ return extended_count
 
 
 
 
 
 
114
 
115
+ def update_canvas(self, current_point):
116
+ """Update the canvas with new drawing points"""
117
+ if len(st.session_state.drawing_points) > 0:
118
+ last_point = st.session_state.drawing_points[-1]
 
 
 
 
119
 
120
+ # Draw line between last point and current point
121
+ st.session_state.draw.line(
122
+ [last_point, current_point],
123
+ fill=st.session_state.current_color,
124
+ width=st.session_state.brush_size
125
+ )
126
+
127
+ st.session_state.drawing_points.append(current_point)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ def clear_canvas(self):
130
+ """Clear the entire canvas"""
131
+ st.session_state.canvas = Image.new('RGB', (600, 400), 'white')
132
+ st.session_state.draw = ImageDraw.Draw(st.session_state.canvas)
133
+ st.session_state.drawing_points = []
134
+ st.session_state.is_drawing = False
135
+
136
+ def run(self):
137
+ # Sidebar for controls
138
+ st.sidebar.title("🎮 Drawing Controls")
139
 
140
+ st.sidebar.markdown("""
141
+ ### How to Draw:
142
+ 1. **Show your hand** to the camera
143
+ 2. **Point with index finger** to start drawing
144
+ 3. **Move your finger** in the air to draw
145
+ 4. **Make a fist** to stop drawing
146
+ 5. **Use controls below** to customize
147
+ """)
148
 
149
+ # Color selection
150
+ st.sidebar.subheader("🎨 Brush Color")
151
+ color_options = {
152
+ "Red": (255, 0, 0),
153
+ "Blue": (0, 0, 255),
154
+ "Green": (0, 255, 0),
155
+ "Purple": (128, 0, 128),
156
+ "Orange": (255, 165, 0),
157
+ "Black": (0, 0, 0)
158
+ }
159
 
160
+ selected_color = st.sidebar.selectbox(
161
+ "Choose color:",
162
+ list(color_options.keys())
163
+ )
164
+ st.session_state.current_color = color_options[selected_color]
165
 
166
+ # Brush size
167
+ st.sidebar.subheader("🖌️ Brush Size")
168
+ st.session_state.brush_size = st.sidebar.slider(
169
+ "Size:", 1, 20, st.session_state.brush_size
170
+ )
 
 
 
 
 
171
 
172
+ # Drawing modes
173
+ st.sidebar.subheader("⚡ Quick Actions")
174
+ col1, col2 = st.sidebar.columns(2)
 
 
 
 
175
 
176
+ with col1:
177
+ if st.button("🗑️ Clear Canvas", use_container_width=True):
178
+ self.clear_canvas()
179
+ st.rerun()
180
+
181
+ with col2:
182
+ if st.button("💾 Save Drawing", use_container_width=True):
183
+ self.save_drawing()
184
+
185
+ # Main content area
186
+ col1, col2 = st.columns([2, 1])
187
 
188
  with col1:
189
+ st.subheader("📹 Live Camera View")
190
+
191
+ # Camera input
192
+ camera_image = st.camera_input("Point your finger to start drawing!", key="drawing_camera")
193
 
194
  if camera_image:
195
+ # Convert to OpenCV format
196
  image = Image.open(camera_image)
197
+ frame = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
198
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
199
 
200
+ # Process with MediaPipe
201
+ results = self.hands.process(frame_rgb)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
+ current_gesture = "Waiting for hand..."
204
+ current_point = None
205
+
206
+ if results.multi_hand_landmarks:
207
+ for hand_landmarks in results.multi_hand_landmarks:
208
+ # Draw hand landmarks on frame
209
+ self.mp_drawing.draw_landmarks(
210
+ frame, hand_landmarks, self.mp_hands.HAND_CONNECTIONS,
211
+ self.mp_drawing.DrawingSpec(color=(0, 255, 0), thickness=2, circle_radius=2),
212
+ self.mp_drawing.DrawingSpec(color=(255, 0, 0), thickness=2)
213
  )
214
 
215
+ # Detect drawing gesture
216
+ is_drawing_gesture, finger_tip = self.detect_drawing_gesture(
217
+ hand_landmarks.landmark, frame.shape[1], frame.shape[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  )
219
+
220
+ if is_drawing_gesture:
221
+ current_gesture = "✍️ Drawing Mode"
222
+ current_point = finger_tip
223
+
224
+ # Scale point to canvas coordinates
225
+ canvas_point = (
226
+ int(finger_tip[0] * 600 / frame.shape[1]),
227
+ int(finger_tip[1] * 400 / frame.shape[0])
228
+ )
229
+
230
+ if st.session_state.is_drawing:
231
+ self.update_canvas(canvas_point)
232
+ else:
233
+ st.session_state.is_drawing = True
234
+ st.session_state.drawing_points = [canvas_point]
235
+ else:
236
+ current_gesture = "✋ Stop Drawing"
237
+ st.session_state.is_drawing = False
238
+
239
+ else:
240
+ current_gesture = "👋 Show your hand to camera"
241
+ st.session_state.is_drawing = False
242
 
243
+ # Add gesture info to frame
244
+ cv2.putText(frame, f"Status: {current_gesture}", (10, 30),
245
+ cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
246
+ cv2.putText(frame, f"Brush: {selected_color}", (10, 60),
247
+ cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
248
+ cv2.putText(frame, f"Size: {st.session_state.brush_size}px", (10, 90),
249
+ cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
250
 
251
+ # Convert back to RGB for display
252
+ result_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
253
+ st.image(result_rgb, caption="Live Camera Feed", use_column_width=True)
254
+
255
+ with col2:
256
+ st.subheader("🎨 Your Drawing Canvas")
257
+
258
+ # Display the canvas
259
+ st.markdown('<div class="canvas-container">', unsafe_allow_html=True)
260
+ st.image(st.session_state.canvas, use_column_width=True, caption="Your Air Drawing")
261
+ st.markdown('</div>', unsafe_allow_html=True)
262
+
263
+ # Drawing statistics
264
+ st.subheader("📊 Drawing Info")
265
+ st.write(f"**Points drawn:** {len(st.session_state.drawing_points)}")
266
+ st.write(f"**Current color:** {selected_color}")
267
+ st.write(f"**Brush size:** {st.session_state.brush_size}px")
268
+ st.write(f"**Drawing mode:** {'Active' if st.session_state.is_drawing else 'Inactive'}")
269
+
270
+ # Quick color buttons
271
+ st.subheader("🎯 Quick Colors")
272
+ color_cols = st.columns(3)
273
+ quick_colors = [("🔴", (255, 0, 0)), ("🔵", (0, 0, 255)), ("🟢", (0, 255, 0))]
274
+
275
+ for i, (emoji, color) in enumerate(quick_colors):
276
+ with color_cols[i]:
277
+ if st.button(emoji, use_container_width=True):
278
+ st.session_state.current_color = color
279
+ st.rerun()
280
+
281
+ def save_drawing(self):
282
+ """Save the current drawing"""
283
+ timestamp = time.strftime("%Y%m%d-%H%M%S")
284
+ filename = f"air_drawing_{timestamp}.png"
285
+ st.session_state.canvas.save(filename)
286
+ st.sidebar.success(f"Drawing saved as {filename}")
287
 
288
  def main():
289
+ app = AirDrawingCanvas()
 
290
  app.run()
291
 
292
  if __name__ == "__main__":