SushantGautam commited on
Commit
be5cb3c
Β·
1 Parent(s): 9054cb0

Add Gradio client integration for submission uploads

Browse files
medvqa/competitions/gi-2025/task_1.py CHANGED
@@ -1,9 +1,10 @@
 
1
  from huggingface_hub import snapshot_download, login, whoami
2
  import sys
3
  import argparse
4
  import os
5
  import subprocess as sp
6
-
7
 
8
  MEDVQA_SUBMIT = True if os.environ.get(
9
  '_MEDVQA_SUBMIT_FLAG_', 'FALSE') == 'TRUE' else False
@@ -14,7 +15,10 @@ args, _ = parser.parse_known_args()
14
 
15
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
16
  submission_file = "submission_task1.py"
17
- min_library = ["datasets", "transformers", 'tqdm']
 
 
 
18
 
19
  print("🌟 ImageCLEFmed-MEDVQA-GI-2025 🌟",
20
  "https://github.com/simula/ImageCLEFmed-MEDVQA-GI-2025")
@@ -27,6 +31,10 @@ except Exception:
27
  print("⚠️⚠️ Not logged in to HuggingFace! Please get your login token from https://huggingface.co/settings/tokens 🌐")
28
  login()
29
 
 
 
 
 
30
  snap_dir = snapshot_download(
31
  repo_id=args.repo_id, allow_patterns=[submission_file, "requirements.txt"])
32
 
@@ -34,8 +42,8 @@ if not os.path.isfile(os.path.join(snap_dir, submission_file)):
34
  raise FileNotFoundError(
35
  f"Submission file '{submission_file}' not found in the repository!")
36
 
37
- if os.path.isfile(os.path.join(snap_dir, "predictions.json")):
38
- os.remove(os.path.join(snap_dir, "predictions.json"))
39
 
40
  print("πŸ“¦ Making sure of the minimum requirements to run the script πŸ“¦")
41
  sp.run(["python", "-m", "pip", "install", "-q"] + min_library, check=True)
@@ -55,3 +63,11 @@ if not MEDVQA_SUBMIT:
55
  print("\n You can now run medvqa validate_and_submit .... command to submit the task.")
56
  else:
57
  print("πŸš€ Preparing for submission πŸš€")
 
 
 
 
 
 
 
 
 
1
+ from gradio_client import Client, handle_file
2
  from huggingface_hub import snapshot_download, login, whoami
3
  import sys
4
  import argparse
5
  import os
6
  import subprocess as sp
7
+ import time
8
 
9
  MEDVQA_SUBMIT = True if os.environ.get(
10
  '_MEDVQA_SUBMIT_FLAG_', 'FALSE') == 'TRUE' else False
 
15
 
16
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
17
  submission_file = "submission_task1.py"
18
+ file_from_validation = "predictions_1.json"
19
+ client = Client("SushantGautam/medvqa")
20
+
21
+ min_library = ["datasets", "transformers", 'tqdm', "gradio_client"]
22
 
23
  print("🌟 ImageCLEFmed-MEDVQA-GI-2025 🌟",
24
  "https://github.com/simula/ImageCLEFmed-MEDVQA-GI-2025")
 
31
  print("⚠️⚠️ Not logged in to HuggingFace! Please get your login token from https://huggingface.co/settings/tokens 🌐")
32
  login()
33
 
34
+ hf_username = whoami()['name']
35
+ assert len(hf_username) > 0, "🚫 HuggingFace login failed for some reason"
36
+ current_timestamp = int(time.time())
37
+
38
  snap_dir = snapshot_download(
39
  repo_id=args.repo_id, allow_patterns=[submission_file, "requirements.txt"])
40
 
 
42
  raise FileNotFoundError(
43
  f"Submission file '{submission_file}' not found in the repository!")
44
 
45
+ if os.path.isfile(os.path.join(snap_dir, file_from_validation)):
46
+ os.remove(os.path.join(snap_dir, file_from_validation))
47
 
48
  print("πŸ“¦ Making sure of the minimum requirements to run the script πŸ“¦")
49
  sp.run(["python", "-m", "pip", "install", "-q"] + min_library, check=True)
 
63
  print("\n You can now run medvqa validate_and_submit .... command to submit the task.")
64
  else:
65
  print("πŸš€ Preparing for submission πŸš€")
66
+ file_path_to_upload = os.path.join(
67
+ snap_dir, f"{hf_username}_{current_timestamp}_task1.py")
68
+ os.copy(os.path.join(snap_dir, file_from_validation), file_path_to_upload)
69
+ result = client.predict(
70
+ file=handle_file(file_path_to_upload),
71
+ api_name="/UploadSubmission"
72
+ )
73
+ print(result)