Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import glob
|
| 4 |
-
import base64
|
| 5 |
-
import mimetypes
|
| 6 |
-
import random
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from time import sleep
|
|
|
|
| 9 |
|
| 10 |
from huggingface_hub import HfApi
|
| 11 |
import threading
|
|
@@ -16,6 +13,17 @@ api = HfApi()
|
|
| 16 |
screenshots = []
|
| 17 |
screenshots_folder = "screenshots"
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def load_screenshots():
|
| 20 |
global screenshots
|
| 21 |
for filename in os.listdir(screenshots_folder):
|
|
@@ -73,7 +81,7 @@ def update_screenshot_info():
|
|
| 73 |
"user_avatar": avatar_url,
|
| 74 |
"user_link": user_link,
|
| 75 |
"color": color_list[i % len(color_list)],
|
| 76 |
-
"rate": space_info.likes
|
| 77 |
})
|
| 78 |
print("Updated:", new_screenshots[i]["user"], new_screenshots[i]["user_link"])
|
| 79 |
except Exception as e:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from datetime import datetime, timezone
|
| 4 |
from time import sleep
|
| 5 |
+
import math
|
| 6 |
|
| 7 |
from huggingface_hub import HfApi
|
| 8 |
import threading
|
|
|
|
| 13 |
screenshots = []
|
| 14 |
screenshots_folder = "screenshots"
|
| 15 |
|
| 16 |
+
def calculate_trending_score(total_likes: int, age_seconds: int) -> float:
|
| 17 |
+
age_in_hours = age_seconds / 3600.0
|
| 18 |
+
DECAY_EXPONENT = 1.8
|
| 19 |
+
BASE_TIME_HOURS = 2.0
|
| 20 |
+
|
| 21 |
+
effective_age_for_decay = max(1.0, age_in_hours + BASE_TIME_HOURS)
|
| 22 |
+
likes_score = math.log10(max(1, total_likes + 1))
|
| 23 |
+
trending_score = likes_score / (effective_age_for_decay ** DECAY_EXPONENT)
|
| 24 |
+
|
| 25 |
+
return trending_score
|
| 26 |
+
|
| 27 |
def load_screenshots():
|
| 28 |
global screenshots
|
| 29 |
for filename in os.listdir(screenshots_folder):
|
|
|
|
| 81 |
"user_avatar": avatar_url,
|
| 82 |
"user_link": user_link,
|
| 83 |
"color": color_list[i % len(color_list)],
|
| 84 |
+
"rate": calculate_trending_score(space_info.likes, (datetime.now(timezone.utc) - space_info.created_at).total_seconds())
|
| 85 |
})
|
| 86 |
print("Updated:", new_screenshots[i]["user"], new_screenshots[i]["user_link"])
|
| 87 |
except Exception as e:
|