qubvel-hf HF staff commited on
Commit
bce71cf
1 Parent(s): 45f46e2

Add mixpanel tracking

Browse files
Files changed (2) hide show
  1. app.py +18 -0
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,18 +1,26 @@
1
  import albumentations as A
2
  import base64
3
  import cv2
 
4
  import gradio as gr
5
  import inspect
6
  import io
7
  import numpy as np
 
8
 
9
  from copy import deepcopy
10
  from functools import wraps
11
  from PIL import Image, ImageDraw
12
  from typing import get_type_hints
 
13
 
14
  from utils import is_not_supported_transform
15
 
 
 
 
 
 
16
 
17
  HEADER = f"""
18
  <div align="center">
@@ -82,6 +90,13 @@ for mask in BASE64_DEFAULT_MASKS:
82
  )
83
 
84
 
 
 
 
 
 
 
 
85
  def run_with_retry(compose):
86
  @wraps(compose)
87
  def wrapper(*args, **kwargs):
@@ -193,6 +208,7 @@ def get_formatted_signature(function_or_class, indentation=4):
193
 
194
  def get_formatted_transform(transform_number):
195
  transform_name = transforms_keys[transform_number]
 
196
  transform = transforms_map[transform_name]
197
  return f"A.{transform.__name__}{get_formatted_signature(transform)}"
198
 
@@ -206,6 +222,8 @@ def get_formatted_transform_docs(transform_number):
206
  def update_augmented_images(image, code):
207
 
208
  augmentation = eval(code)
 
 
209
  compose = A.Compose(
210
  [augmentation],
211
  bbox_params=A.BboxParams(format="pascal_voc", label_fields=["category_id"]),
 
1
  import albumentations as A
2
  import base64
3
  import cv2
4
+ import logging
5
  import gradio as gr
6
  import inspect
7
  import io
8
  import numpy as np
9
+ import os
10
 
11
  from copy import deepcopy
12
  from functools import wraps
13
  from PIL import Image, ImageDraw
14
  from typing import get_type_hints
15
+ from mixpanel import Mixpanel
16
 
17
  from utils import is_not_supported_transform
18
 
19
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
20
+ logger = logging.getLogger(__name__)
21
+
22
+ MIXPANEL_TOKEN = os.getenv("MIXPANEL_TOKEN")
23
+ mp = Mixpanel(MIXPANEL_TOKEN)
24
 
25
  HEADER = f"""
26
  <div align="center">
 
90
  )
91
 
92
 
93
+ def track_event(event_name, user_id="unknown", properties=None):
94
+ if properties is None:
95
+ properties = {}
96
+ mp.track(user_id, event_name, properties)
97
+ logger.info(f"Event tracked: {event_name} - {properties}")
98
+
99
+
100
  def run_with_retry(compose):
101
  @wraps(compose)
102
  def wrapper(*args, **kwargs):
 
208
 
209
  def get_formatted_transform(transform_number):
210
  transform_name = transforms_keys[transform_number]
211
+ track_event("transform_selected", properties={"transform_name": transform_name})
212
  transform = transforms_map[transform_name]
213
  return f"A.{transform.__name__}{get_formatted_signature(transform)}"
214
 
 
222
  def update_augmented_images(image, code):
223
 
224
  augmentation = eval(code)
225
+ track_event("transform_applied", properties={"transform_name": augmentation.__class__.__name__, "code": code})
226
+
227
  compose = A.Compose(
228
  [augmentation],
229
  bbox_params=A.BboxParams(format="pascal_voc", label_fields=["category_id"]),
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  albumentations
2
- Pillow
 
 
1
  albumentations
2
+ Pillow
3
+ mixpanel