Spaces:
Runtime error
Runtime error
Aaron Mueller
commited on
Commit
·
e7e9a2c
1
Parent(s):
df72705
fix upload for JSONs
Browse files
app.py
CHANGED
@@ -81,17 +81,26 @@ def init_leaderboard(dataframe, track):
|
|
81 |
interactive=False,
|
82 |
)
|
83 |
|
|
|
84 |
def process_json(temp_file):
|
85 |
-
if
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
with open(
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
|
97 |
demo = gr.Blocks(css=custom_css)
|
@@ -165,9 +174,14 @@ with demo:
|
|
165 |
interactive=True
|
166 |
)
|
167 |
|
168 |
-
upload_button = gr.UploadButton(label="Upload predictions", file_types
|
169 |
-
|
170 |
-
upload_button.upload(
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
submit_button = gr.Button("Submit Eval")
|
173 |
submission_result = gr.Markdown()
|
|
|
81 |
interactive=False,
|
82 |
)
|
83 |
|
84 |
+
submitted_predictions = {}
|
85 |
def process_json(temp_file):
|
86 |
+
if temp_file is None:
|
87 |
+
return {}
|
88 |
+
|
89 |
+
# Handle file upload
|
90 |
+
try:
|
91 |
+
file_path = temp_file.name
|
92 |
+
if file_path.endswith('.gz'):
|
93 |
+
with gzip.open(file_path, 'rt') as f:
|
94 |
+
data = json.load(f)
|
95 |
+
submitted_predictions.update(data)
|
96 |
+
else:
|
97 |
+
with open(file_path, 'r') as f:
|
98 |
+
data = json.load(f)
|
99 |
+
submitted_predictions.update(data)
|
100 |
+
except Exception as e:
|
101 |
+
raise gr.Error(f"Error processing file: {str(e)}")
|
102 |
+
|
103 |
+
return data
|
104 |
|
105 |
|
106 |
demo = gr.Blocks(css=custom_css)
|
|
|
174 |
interactive=True
|
175 |
)
|
176 |
|
177 |
+
upload_button = gr.UploadButton(label="Upload predictions", file_types=[".json", ".gz"], file_count="single")
|
178 |
+
output_json = gr.JSON(label="Processed JSON")
|
179 |
+
upload_button.upload(
|
180 |
+
fn=process_json,
|
181 |
+
inputs=upload_button,
|
182 |
+
outputs=output_json,
|
183 |
+
api_name="upload_json"
|
184 |
+
)
|
185 |
|
186 |
submit_button = gr.Button("Submit Eval")
|
187 |
submission_result = gr.Markdown()
|