Spaces:
Running
Running
Update usage_logging.py
Browse files- usage_logging.py +5 -4
usage_logging.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
|
| 3 |
----------------
|
| 4 |
Purpose:
|
| 5 |
This module implements privacy-preserving telemetry for the
|
|
@@ -114,7 +114,7 @@ def _geo_lookup(ip: str) -> dict:
|
|
| 114 |
return {"country": "Unknown", "city": "Unknown"}
|
| 115 |
|
| 116 |
|
| 117 |
-
def append_visit_to_dataset(country: str, city: str):
|
| 118 |
api = _hf_api()
|
| 119 |
if not api:
|
| 120 |
return
|
|
@@ -129,7 +129,7 @@ def append_visit_to_dataset(country: str, city: str):
|
|
| 129 |
"space_url": SPACE_URL,
|
| 130 |
"country": country,
|
| 131 |
"city": city,
|
| 132 |
-
"event":
|
| 133 |
}
|
| 134 |
|
| 135 |
new_content = (
|
|
@@ -155,6 +155,7 @@ def record_visit(request: gr.Request):
|
|
| 155 |
geo = _geo_lookup(ip) if ip else {"country": "Unknown", "city": "Unknown"}
|
| 156 |
append_visit_to_dataset(
|
| 157 |
country=geo["country"],
|
| 158 |
-
city=geo["city"]
|
|
|
|
| 159 |
)
|
| 160 |
return
|
|
|
|
| 1 |
"""
|
| 2 |
+
usage_logging.py
|
| 3 |
----------------
|
| 4 |
Purpose:
|
| 5 |
This module implements privacy-preserving telemetry for the
|
|
|
|
| 114 |
return {"country": "Unknown", "city": "Unknown"}
|
| 115 |
|
| 116 |
|
| 117 |
+
def append_visit_to_dataset(country: str, city: str, event_type: str = "usage_start"):
|
| 118 |
api = _hf_api()
|
| 119 |
if not api:
|
| 120 |
return
|
|
|
|
| 129 |
"space_url": SPACE_URL,
|
| 130 |
"country": country,
|
| 131 |
"city": city,
|
| 132 |
+
"event": event_type,
|
| 133 |
}
|
| 134 |
|
| 135 |
new_content = (
|
|
|
|
| 155 |
geo = _geo_lookup(ip) if ip else {"country": "Unknown", "city": "Unknown"}
|
| 156 |
append_visit_to_dataset(
|
| 157 |
country=geo["country"],
|
| 158 |
+
city=geo["city"],
|
| 159 |
+
event_type="usage_start"
|
| 160 |
)
|
| 161 |
return
|