Commit
·
9e4515d
1
Parent(s):
1463aae
Add Gradio interface for viewing and uploading submissions
Browse files- README.md +3 -0
- gradio_interface.py +156 -0
README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
# MedVQA
|
2 |
|
3 |
A CLI tool for MedVQA competition (https://github.com/simula/ImageCLEFmed-MEDVQA-GI-2025).
|
|
|
1 |
+
---
|
2 |
+
sdk: gradio
|
3 |
+
---
|
4 |
# MedVQA
|
5 |
|
6 |
A CLI tool for MedVQA competition (https://github.com/simula/ImageCLEFmed-MEDVQA-GI-2025).
|
gradio_interface.py
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = [
|
7 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
8 |
+
timedelta(hours=1)},
|
9 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
10 |
+
timedelta(days=1)},
|
11 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
12 |
+
timedelta(minutes=30)},
|
13 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
14 |
+
timedelta(hours=1)},
|
15 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
16 |
+
timedelta(days=1)},
|
17 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
18 |
+
timedelta(minutes=30)},
|
19 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
20 |
+
timedelta(hours=1)},
|
21 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
22 |
+
timedelta(days=1)},
|
23 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
24 |
+
timedelta(minutes=30)},
|
25 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
26 |
+
timedelta(days=1)},
|
27 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
28 |
+
timedelta(minutes=30)},
|
29 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
30 |
+
timedelta(hours=1)},
|
31 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
32 |
+
timedelta(days=1)},
|
33 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
34 |
+
timedelta(minutes=30)},
|
35 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
36 |
+
timedelta(days=1)},
|
37 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
38 |
+
timedelta(minutes=30)},
|
39 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
40 |
+
timedelta(hours=1)},
|
41 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
42 |
+
timedelta(days=1)},
|
43 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
44 |
+
timedelta(minutes=30)},
|
45 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
46 |
+
timedelta(days=1)},
|
47 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
48 |
+
timedelta(minutes=30)},
|
49 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
50 |
+
timedelta(hours=1)},
|
51 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
52 |
+
timedelta(days=1)},
|
53 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
54 |
+
timedelta(minutes=30)},
|
55 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
56 |
+
timedelta(days=1)},
|
57 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
58 |
+
timedelta(minutes=30)},
|
59 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
60 |
+
timedelta(hours=1)},
|
61 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
62 |
+
timedelta(days=1)},
|
63 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
64 |
+
timedelta(minutes=30)},
|
65 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
66 |
+
timedelta(days=1)},
|
67 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
68 |
+
timedelta(minutes=30)},
|
69 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
70 |
+
timedelta(hours=1)},
|
71 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
72 |
+
timedelta(days=1)},
|
73 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
74 |
+
timedelta(minutes=30)},
|
75 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
76 |
+
timedelta(days=1)},
|
77 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
78 |
+
timedelta(minutes=30)},
|
79 |
+
{"user": "User1", "task": "task1", "submitted_time": datetime.now() -
|
80 |
+
timedelta(hours=1)},
|
81 |
+
{"user": "User2", "task": "task2", "submitted_time": datetime.now() -
|
82 |
+
timedelta(days=1)},
|
83 |
+
{"user": "User3", "task": "task1", "submitted_time": datetime.now() -
|
84 |
+
timedelta(minutes=30)},
|
85 |
+
# ... add more sample data as needed ...
|
86 |
+
]
|
87 |
+
|
88 |
+
|
89 |
+
def time_ago(submitted_time):
|
90 |
+
delta = datetime.now() - submitted_time
|
91 |
+
if delta.days > 0:
|
92 |
+
return f"{delta.days} days ago"
|
93 |
+
elif delta.seconds // 3600 > 0:
|
94 |
+
return f"{delta.seconds // 3600} hours ago"
|
95 |
+
elif delta.seconds // 60 > 0:
|
96 |
+
return f"{delta.seconds // 60} minutes ago"
|
97 |
+
else:
|
98 |
+
return "just now"
|
99 |
+
|
100 |
+
|
101 |
+
def filter_submissions(task_type, search_query):
|
102 |
+
if search_query == "":
|
103 |
+
filtered = [s for s in submissions if task_type ==
|
104 |
+
"all" or s["task"] == task_type]
|
105 |
+
else:
|
106 |
+
filtered = [s for s in submissions if (
|
107 |
+
task_type == "all" or s["task"] == task_type) and search_query.lower() in s["user"].lower()]
|
108 |
+
return [{"user": s["user"], "task": s["task"], "submitted_time": time_ago(s["submitted_time"])} for s in filtered]
|
109 |
+
|
110 |
+
|
111 |
+
def display_submissions(task_type="all", search_query=""):
|
112 |
+
filtered_submissions = filter_submissions(task_type, search_query)
|
113 |
+
return [[s["user"], s["task"], s["submitted_time"]] for s in filtered_submissions]
|
114 |
+
|
115 |
+
|
116 |
+
def add_submission(file):
|
117 |
+
try:
|
118 |
+
new_submissions = json.load(file)
|
119 |
+
for submission in new_submissions:
|
120 |
+
submission["submitted_time"] = datetime.strptime(
|
121 |
+
submission["submitted_time"], "%Y-%m-%d %H:%M:%S")
|
122 |
+
submissions.append(submission)
|
123 |
+
return "Submissions added successfully!"
|
124 |
+
except Exception as e:
|
125 |
+
return f"Error: {str(e)}"
|
126 |
+
|
127 |
+
|
128 |
+
# Define Gradio interface components
|
129 |
+
output_table = gr.Dataframe(
|
130 |
+
headers=["User", "Task", "Submitted Time"], value=display_submissions(), scale=5,)
|
131 |
+
task_type_dropdown = gr.Dropdown(
|
132 |
+
choices=["all", "task1", "task2"], value="all", label="Task Type")
|
133 |
+
search_box = gr.Textbox(value="", label="Search User")
|
134 |
+
upload_button = gr.File(label="Upload JSON", file_types=["json"])
|
135 |
+
|
136 |
+
# Create a tabbed interface
|
137 |
+
with gr.Blocks(title="ImageCLEFmed-MEDVQA-GI-2025 Submissions") as demo:
|
138 |
+
with gr.Tab("View Submissions"):
|
139 |
+
gr.Interface(
|
140 |
+
fn=display_submissions,
|
141 |
+
inputs=[task_type_dropdown, search_box],
|
142 |
+
outputs=output_table,
|
143 |
+
title="ImageCLEFmed-MEDVQA-GI-2025 Submissions",
|
144 |
+
description="Filter and search submissions by task type and user."
|
145 |
+
)
|
146 |
+
with gr.Tab("Upload Submission", visible=False):
|
147 |
+
gr.Interface(
|
148 |
+
api_name="UploadSubmission",
|
149 |
+
fn=add_submission,
|
150 |
+
inputs=upload_button,
|
151 |
+
outputs="text",
|
152 |
+
title="Upload Submissions",
|
153 |
+
description="Upload a JSON file to add new submissions."
|
154 |
+
)
|
155 |
+
|
156 |
+
demo.launch()
|