Spaces:
Running
Running
Commit
·
c7c831b
1
Parent(s):
d602371
Refactor submission handling to use hub_path instead of hub_dir and improve logging for downloaded submissions
Browse files- gradio_interface.py +9 -6
gradio_interface.py
CHANGED
|
@@ -9,19 +9,21 @@ from huggingface_hub import whoami
|
|
| 9 |
print("Account token used to connect to HuggingFace: ", whoami()['name'])
|
| 10 |
|
| 11 |
SUBMISSION_REPO = "SushantGautam/medvqa-submissions"
|
| 12 |
-
|
| 13 |
|
| 14 |
submissions = None # [{"user": u, "task": t, "submitted_time": ts}]
|
| 15 |
|
| 16 |
|
| 17 |
def refresh_submissions():
|
| 18 |
-
global
|
| 19 |
-
if
|
| 20 |
-
shutil.rmtree(
|
|
|
|
| 21 |
|
| 22 |
hub_path = snapshot_download(repo_type="dataset",
|
| 23 |
repo_id=SUBMISSION_REPO, allow_patterns=['*.json'])
|
| 24 |
-
|
|
|
|
| 25 |
json_files = [f for f in os.listdir(hub_path) if f.endswith('.json')]
|
| 26 |
print("Downloaded submissions: ", json_files)
|
| 27 |
submissions = []
|
|
@@ -30,7 +32,6 @@ def refresh_submissions():
|
|
| 30 |
".json", "").split("-_-_-")
|
| 31 |
submissions.append({"user": username, "task": task,
|
| 32 |
"submitted_time": sub_timestamp})
|
| 33 |
-
|
| 34 |
return hub_path
|
| 35 |
|
| 36 |
|
|
@@ -64,6 +65,8 @@ def filter_submissions(task_type, search_query):
|
|
| 64 |
|
| 65 |
|
| 66 |
def display_submissions(task_type="all", search_query=""):
|
|
|
|
|
|
|
| 67 |
filtered_submissions = filter_submissions(task_type, search_query)
|
| 68 |
return [[s["user"], s["task"], s["submitted_time"]] for s in filtered_submissions]
|
| 69 |
|
|
|
|
| 9 |
print("Account token used to connect to HuggingFace: ", whoami()['name'])
|
| 10 |
|
| 11 |
SUBMISSION_REPO = "SushantGautam/medvqa-submissions"
|
| 12 |
+
hub_path = None
|
| 13 |
|
| 14 |
submissions = None # [{"user": u, "task": t, "submitted_time": ts}]
|
| 15 |
|
| 16 |
|
| 17 |
def refresh_submissions():
|
| 18 |
+
global hub_path, submissions
|
| 19 |
+
if hub_path and Path(hub_path).exists():
|
| 20 |
+
shutil.rmtree(hub_path, ignore_errors=True)
|
| 21 |
+
print("Deleted existing submissions")
|
| 22 |
|
| 23 |
hub_path = snapshot_download(repo_type="dataset",
|
| 24 |
repo_id=SUBMISSION_REPO, allow_patterns=['*.json'])
|
| 25 |
+
print("Downloaded submissions to: ", hub_path)
|
| 26 |
+
print("os.listdir(hub_path):", os.listdir(hub_path))
|
| 27 |
json_files = [f for f in os.listdir(hub_path) if f.endswith('.json')]
|
| 28 |
print("Downloaded submissions: ", json_files)
|
| 29 |
submissions = []
|
|
|
|
| 32 |
".json", "").split("-_-_-")
|
| 33 |
submissions.append({"user": username, "task": task,
|
| 34 |
"submitted_time": sub_timestamp})
|
|
|
|
| 35 |
return hub_path
|
| 36 |
|
| 37 |
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
def display_submissions(task_type="all", search_query=""):
|
| 68 |
+
if submissions is None:
|
| 69 |
+
refresh_submissions()
|
| 70 |
filtered_submissions = filter_submissions(task_type, search_query)
|
| 71 |
return [[s["user"], s["task"], s["submitted_time"]] for s in filtered_submissions]
|
| 72 |
|