Spaces:
Running
Running
Commit
·
f9f09f4
1
Parent(s):
33f88d6
Refactor get_hub_path to manage hub directory and ensure clean downloads
Browse files- gradio_interface.py +18 -1
gradio_interface.py
CHANGED
|
@@ -2,14 +2,31 @@ import gradio as gr
|
|
| 2 |
import json
|
| 3 |
from datetime import datetime, timezone, timedelta
|
| 4 |
from huggingface_hub import upload_file, snapshot_download
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
SUBMISSION_REPO = "SushantGautam/medvqa-submissions"
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def get_hub_path():
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
| 12 |
print(f"{SUBMISSION_REPO} downloaded to {get_hub_path()}")
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
submissions = [
|
| 15 |
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
|
|
|
| 2 |
import json
|
| 3 |
from datetime import datetime, timezone, timedelta
|
| 4 |
from huggingface_hub import upload_file, snapshot_download
|
| 5 |
+
import shutil
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
SUBMISSION_REPO = "SushantGautam/medvqa-submissions"
|
| 10 |
+
hub_dir = None
|
| 11 |
|
| 12 |
|
| 13 |
def get_hub_path():
|
| 14 |
+
global hub_dir
|
| 15 |
+
if hub_dir and Path(hub_dir).exists():
|
| 16 |
+
shutil.rmtree(hub_dir, ignore_errors=True)
|
| 17 |
+
|
| 18 |
+
hub_path = snapshot_download(
|
| 19 |
+
repo_id=SUBMISSION_REPO, allow_patterns=['*.json'])
|
| 20 |
+
hub_dir = os.path.dirname(hub_path) # More robust than split
|
| 21 |
+
return hub_path
|
| 22 |
|
| 23 |
|
| 24 |
+
hub_path = get_hub_path()
|
| 25 |
+
|
| 26 |
print(f"{SUBMISSION_REPO} downloaded to {get_hub_path()}")
|
| 27 |
+
# remove strings after snapshot in hub_path
|
| 28 |
+
hub_dir = hub_path.split("snapshot")[0] + "snapshot"
|
| 29 |
+
|
| 30 |
|
| 31 |
submissions = [
|
| 32 |
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|