Spaces:
Running
Running
Duplicate parse json function
Browse files
app.py
CHANGED
@@ -287,29 +287,6 @@ leaderboard_table = gr.Dataframe(
|
|
287 |
datatype=['str', 'number', 'str', 'number', 'str', 'str', 'str']
|
288 |
)
|
289 |
|
290 |
-
def parse_model_response(response):
|
291 |
-
try:
|
292 |
-
# Debug print
|
293 |
-
print(f"Raw model response: {response}")
|
294 |
-
|
295 |
-
# First try to parse the entire response as JSON
|
296 |
-
try:
|
297 |
-
data = json.loads(response)
|
298 |
-
return str(data.get('result', 'N/A')), data.get('feedback', 'N/A')
|
299 |
-
except json.JSONDecodeError:
|
300 |
-
# If that fails (typically for smaller models), try to find JSON within the response
|
301 |
-
json_match = re.search(r'{.*}', response)
|
302 |
-
if json_match:
|
303 |
-
data = json.loads(json_match.group(0))
|
304 |
-
return str(data.get('result', 'N/A')), data.get('feedback', 'N/A')
|
305 |
-
else:
|
306 |
-
return 'Error', f"Failed to parse response: {response}"
|
307 |
-
|
308 |
-
except Exception as e:
|
309 |
-
# Debug print for error case
|
310 |
-
print(f"Failed to parse response: {str(e)}")
|
311 |
-
return 'Error', f"Failed to parse response: {response}"
|
312 |
-
|
313 |
def get_leaderboard_stats():
|
314 |
"""Get summary statistics for the leaderboard."""
|
315 |
try:
|
|
|
287 |
datatype=['str', 'number', 'str', 'number', 'str', 'str', 'str']
|
288 |
)
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
def get_leaderboard_stats():
|
291 |
"""Get summary statistics for the leaderboard."""
|
292 |
try:
|