SushantGautam commited on
Commit
12df570
·
1 Parent(s): 63a9f6c
Files changed (1) hide show
  1. gradio_interface.py +25 -6
gradio_interface.py CHANGED
@@ -1,6 +1,9 @@
1
  import gradio as gr
2
- from datetime import datetime, timedelta
3
  import json
 
 
 
 
4
 
5
  # Sample data structure to hold submission information
6
  submissions = [
@@ -104,11 +107,27 @@ def display_submissions(task_type="all", search_query=""):
104
 
105
 
106
  def add_submission(file):
107
- with open(file, 'r', encoding='utf-8') as f:
108
- data = json.load(f)
109
- print("Adding submission...", data)
110
- print(data)
111
- return "Submissions added successfully!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
 
114
  def refresh_page():
 
1
  import gradio as gr
 
2
  import json
3
+ from datetime import datetime, timezone, timedelta
4
+ from huggingface_hub import upload_file
5
+ SUBMISSION_REPO = "SushantGautam/medvqa-submissions"
6
+
7
 
8
  # Sample data structure to hold submission information
9
  submissions = [
 
107
 
108
 
109
  def add_submission(file):
110
+ try:
111
+ with open(file, 'r', encoding='utf-8') as f:
112
+ data = json.load(f)
113
+ username, sub_timestamp, task = file.replace(
114
+ ".json", "").split("|")
115
+ submission_time = datetime.fromtimestamp(
116
+ sub_timestamp / 1000, tz=timezone.utc)
117
+ assert task in ["task1", "task2"], "Invalid task type"
118
+ assert len(username) > 0, "Invalid username"
119
+ assert submission_time < datetime.now(), "Invalid submission time"
120
+ print("Adding submission...", username, task, submission_time)
121
+ upload_file(
122
+ path_or_fileobj=file,
123
+ path_in_repo="task1/"+file.split("/")[-1],
124
+ repo_id=SUBMISSION_REPO
125
+ )
126
+ submissions.append(
127
+ {"user": username, "task": task, "submitted_time": submission_time})
128
+ return "💪🏆🎉 Submissions added successfully! Visit this URL ⬆️ to see the entry."
129
+ except Exception as e:
130
+ raise Exception(f"Error adding submission: {e}")
131
 
132
 
133
  def refresh_page():