Commit
·
257177b
1
Parent(s):
278edea
Update submission timestamps to use UTC for consistent time handling
Browse files- gradio_interface.py +42 -39
gradio_interface.py
CHANGED
|
@@ -12,99 +12,102 @@ SUBMISSION_REPO = "SushantGautam/medvqa-submissions"
|
|
| 12 |
hub_dir = None
|
| 13 |
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
global hub_dir
|
| 17 |
if hub_dir and Path(hub_dir).exists():
|
| 18 |
shutil.rmtree(hub_dir, ignore_errors=True)
|
| 19 |
|
| 20 |
hub_path = snapshot_download(repo_type="dataset",
|
| 21 |
repo_id=SUBMISSION_REPO, allow_patterns=['*.json'])
|
| 22 |
hub_dir = os.path.dirname(hub_path) # More robust than split
|
|
|
|
|
|
|
| 23 |
return hub_path
|
| 24 |
|
| 25 |
|
| 26 |
-
hub_path =
|
| 27 |
|
| 28 |
-
print(f"{SUBMISSION_REPO} downloaded to {
|
| 29 |
# remove strings after snapshot in hub_path
|
| 30 |
hub_dir = hub_path.split("snapshot")[0] + "snapshot"
|
| 31 |
|
| 32 |
|
| 33 |
submissions = [
|
| 34 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 35 |
timedelta(hours=1)},
|
| 36 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 37 |
timedelta(days=1)},
|
| 38 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 39 |
timedelta(minutes=30)},
|
| 40 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 41 |
timedelta(hours=1)},
|
| 42 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 43 |
timedelta(days=1)},
|
| 44 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 45 |
timedelta(minutes=30)},
|
| 46 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 47 |
timedelta(hours=1)},
|
| 48 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 49 |
timedelta(days=1)},
|
| 50 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 51 |
timedelta(minutes=30)},
|
| 52 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 53 |
timedelta(days=1)},
|
| 54 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 55 |
timedelta(minutes=30)},
|
| 56 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 57 |
timedelta(hours=1)},
|
| 58 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 59 |
timedelta(days=1)},
|
| 60 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 61 |
timedelta(minutes=30)},
|
| 62 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 63 |
timedelta(days=1)},
|
| 64 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 65 |
timedelta(minutes=30)},
|
| 66 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 67 |
timedelta(hours=1)},
|
| 68 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 69 |
timedelta(days=1)},
|
| 70 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 71 |
timedelta(minutes=30)},
|
| 72 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 73 |
timedelta(days=1)},
|
| 74 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 75 |
timedelta(minutes=30)},
|
| 76 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 77 |
timedelta(hours=1)},
|
| 78 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 79 |
timedelta(days=1)},
|
| 80 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 81 |
timedelta(minutes=30)},
|
| 82 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 83 |
timedelta(days=1)},
|
| 84 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 85 |
timedelta(minutes=30)},
|
| 86 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 87 |
timedelta(hours=1)},
|
| 88 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 89 |
timedelta(days=1)},
|
| 90 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 91 |
timedelta(minutes=30)},
|
| 92 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 93 |
timedelta(days=1)},
|
| 94 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 95 |
timedelta(minutes=30)},
|
| 96 |
-
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
| 97 |
timedelta(hours=1)},
|
| 98 |
-
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
| 99 |
timedelta(days=1)},
|
| 100 |
-
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
| 101 |
timedelta(minutes=30)},
|
|
|
|
| 102 |
# ... add more sample data as needed ...
|
| 103 |
]
|
| 104 |
|
| 105 |
|
| 106 |
def time_ago(submitted_time):
|
| 107 |
-
delta = datetime.now() - submitted_time
|
| 108 |
if delta.days > 0:
|
| 109 |
return f"{delta.days} days ago"
|
| 110 |
elif delta.seconds // 3600 > 0:
|
|
|
|
| 12 |
hub_dir = None
|
| 13 |
|
| 14 |
|
| 15 |
+
def refresh_submissions():
|
| 16 |
+
global hub_dir, submissions
|
| 17 |
if hub_dir and Path(hub_dir).exists():
|
| 18 |
shutil.rmtree(hub_dir, ignore_errors=True)
|
| 19 |
|
| 20 |
hub_path = snapshot_download(repo_type="dataset",
|
| 21 |
repo_id=SUBMISSION_REPO, allow_patterns=['*.json'])
|
| 22 |
hub_dir = os.path.dirname(hub_path) # More robust than split
|
| 23 |
+
submissions = [{"user": u, "task": t, "submitted_time": ts} for f in os.listdir(
|
| 24 |
+
hub_path) if f.endswith('.json') for u, ts, t in [f.replace(".json", "").split("-_-_-")]]
|
| 25 |
return hub_path
|
| 26 |
|
| 27 |
|
| 28 |
+
hub_path = refresh_submissions()
|
| 29 |
|
| 30 |
+
print(f"{SUBMISSION_REPO} downloaded to {hub_path}")
|
| 31 |
# remove strings after snapshot in hub_path
|
| 32 |
hub_dir = hub_path.split("snapshot")[0] + "snapshot"
|
| 33 |
|
| 34 |
|
| 35 |
submissions = [
|
| 36 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 37 |
timedelta(hours=1)},
|
| 38 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 39 |
timedelta(days=1)},
|
| 40 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 41 |
timedelta(minutes=30)},
|
| 42 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 43 |
timedelta(hours=1)},
|
| 44 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 45 |
timedelta(days=1)},
|
| 46 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 47 |
timedelta(minutes=30)},
|
| 48 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 49 |
timedelta(hours=1)},
|
| 50 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 51 |
timedelta(days=1)},
|
| 52 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 53 |
timedelta(minutes=30)},
|
| 54 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 55 |
timedelta(days=1)},
|
| 56 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 57 |
timedelta(minutes=30)},
|
| 58 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 59 |
timedelta(hours=1)},
|
| 60 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 61 |
timedelta(days=1)},
|
| 62 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 63 |
timedelta(minutes=30)},
|
| 64 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 65 |
timedelta(days=1)},
|
| 66 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 67 |
timedelta(minutes=30)},
|
| 68 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 69 |
timedelta(hours=1)},
|
| 70 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 71 |
timedelta(days=1)},
|
| 72 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 73 |
timedelta(minutes=30)},
|
| 74 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 75 |
timedelta(days=1)},
|
| 76 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 77 |
timedelta(minutes=30)},
|
| 78 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 79 |
timedelta(hours=1)},
|
| 80 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 81 |
timedelta(days=1)},
|
| 82 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 83 |
timedelta(minutes=30)},
|
| 84 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 85 |
timedelta(days=1)},
|
| 86 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 87 |
timedelta(minutes=30)},
|
| 88 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 89 |
timedelta(hours=1)},
|
| 90 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 91 |
timedelta(days=1)},
|
| 92 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 93 |
timedelta(minutes=30)},
|
| 94 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 95 |
timedelta(days=1)},
|
| 96 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 97 |
timedelta(minutes=30)},
|
| 98 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 99 |
timedelta(hours=1)},
|
| 100 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now(timezone.utc) -
|
| 101 |
timedelta(days=1)},
|
| 102 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now(timezone.utc) -
|
| 103 |
timedelta(minutes=30)},
|
| 104 |
+
|
| 105 |
# ... add more sample data as needed ...
|
| 106 |
]
|
| 107 |
|
| 108 |
|
| 109 |
def time_ago(submitted_time):
|
| 110 |
+
delta = datetime.now(timezone.utc) - submitted_time
|
| 111 |
if delta.days > 0:
|
| 112 |
return f"{delta.days} days ago"
|
| 113 |
elif delta.seconds // 3600 > 0:
|