$P@D$3RV£R commited on
Commit
1457ce4
·
1 Parent(s): f22360e

Add Total Cumulative Visits (HF Space visits) to bottom stats bar

Browse files
Files changed (2) hide show
  1. app.py +23 -1
  2. templates/tagger.html +5 -1
app.py CHANGED
@@ -131,6 +131,27 @@ def save_stats(stats):
131
  import traceback
132
  traceback.print_exc()
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  def track_visit():
135
  """Track a visit - cumulative and persistent"""
136
  try:
@@ -304,7 +325,8 @@ def tagger():
304
  max_sets=max_sets,
305
  total_visits=total_visits,
306
  unique_visitors=unique_count,
307
- countries_count=countries_count
 
308
  )
309
 
310
  def save_annotations_to_csv():
 
131
  import traceback
132
  traceback.print_exc()
133
 
134
+ def get_hf_space_visits():
135
+ """Try to get HuggingFace Space visit count from the Space page"""
136
+ try:
137
+ space_url = "https://huggingface.co/spaces/0001AMA/auto_object_annotator_0.0.4"
138
+ response = requests.get(space_url, timeout=5)
139
+ if response.status_code == 200:
140
+ # Try to find visit count in the HTML (this is a workaround since there's no API)
141
+ import re
142
+ # Look for common patterns that might contain visit counts
143
+ # This is a heuristic approach - HF may change their HTML structure
144
+ html = response.text
145
+ # Try to find numbers that might be visit counts (look for patterns like "302", "1.37k", etc.)
146
+ # Note: This is fragile and may need adjustment based on actual HF HTML structure
147
+ # For now, return None if we can't find it reliably
148
+ pass
149
+ except Exception as e:
150
+ print(f"Could not fetch HF Space visits: {e}")
151
+
152
+ # Return None - we'll use app's own tracking as fallback
153
+ return None
154
+
155
  def track_visit():
156
  """Track a visit - cumulative and persistent"""
157
  try:
 
325
  max_sets=max_sets,
326
  total_visits=total_visits,
327
  unique_visitors=unique_count,
328
+ countries_count=countries_count,
329
+ hf_space_visits=hf_space_visits
330
  )
331
 
332
  def save_annotations_to_csv():
templates/tagger.html CHANGED
@@ -845,7 +845,7 @@ function setupCanvas(imageSrc, canvasId, imageName, labels) {
845
  </script>
846
 
847
  <!-- Statistics Bar at Bottom -->
848
- <div style="position: fixed; bottom: 0; left: 0; right: 0; background: #f8f9fa; border-top: 2px solid #007bff; padding: 10px 20px; display: flex; justify-content: center; align-items: center; gap: 40px; z-index: 1000; box-shadow: 0 -2px 10px rgba(0,0,0,0.1);">
849
  <div style="text-align: center;">
850
  <div style="font-size: 24px; font-weight: bold; color: #007bff;">{{ total_visits }}</div>
851
  <div style="font-size: 12px; color: #666;">Total Visits</div>
@@ -858,6 +858,10 @@ function setupCanvas(imageSrc, canvasId, imageName, labels) {
858
  <div style="font-size: 24px; font-weight: bold; color: #dc3545;">{{ countries_count }}</div>
859
  <div style="font-size: 12px; color: #666;">Countries</div>
860
  </div>
 
 
 
 
861
  </div>
862
 
863
  </body>
 
845
  </script>
846
 
847
  <!-- Statistics Bar at Bottom -->
848
+ <div style="position: fixed; bottom: 0; left: 0; right: 0; background: #f8f9fa; border-top: 2px solid #007bff; padding: 10px 20px; display: flex; justify-content: center; align-items: center; gap: 30px; z-index: 1000; box-shadow: 0 -2px 10px rgba(0,0,0,0.1);">
849
  <div style="text-align: center;">
850
  <div style="font-size: 24px; font-weight: bold; color: #007bff;">{{ total_visits }}</div>
851
  <div style="font-size: 12px; color: #666;">Total Visits</div>
 
858
  <div style="font-size: 24px; font-weight: bold; color: #dc3545;">{{ countries_count }}</div>
859
  <div style="font-size: 12px; color: #666;">Countries</div>
860
  </div>
861
+ <div style="text-align: center;">
862
+ <div style="font-size: 24px; font-weight: bold; color: #6c757d;">{{ hf_space_visits }}</div>
863
+ <div style="font-size: 12px; color: #666;">Total Cumulative Visits</div>
864
+ </div>
865
  </div>
866
 
867
  </body>