delightfulrachel commited on
Commit
8d6cfc5
·
verified ·
1 Parent(s): fa0da49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -239,18 +239,27 @@ def extract_validation_metrics(validation_text):
239
 
240
  if start_idx != -1 and end_idx != -1 and start_idx < end_idx:
241
  json_str = validation_text[start_idx:end_idx]
242
- data = json.loads(json_str)
 
243
 
244
- # Extract the required metrics
245
- metrics = {
246
- "quality_rating": data.get("quality_rating", 0),
247
- "accuracy": data.get("accuracy", 0.0),
248
- "completeness": data.get("completeness", 0.0),
249
- "best_practices_alignment": data.get("best_practices_alignment", 0.0)
250
- }
251
-
252
- return metrics
253
- return None
 
 
 
 
 
 
 
 
254
  except Exception as e:
255
  print(f"Error extracting metrics: {e}")
256
  return None
 
239
 
240
  if start_idx != -1 and end_idx != -1 and start_idx < end_idx:
241
  json_str = validation_text[start_idx:end_idx]
242
+ # Print for debugging
243
+ print("Extracted JSON:", json_str)
244
 
245
+ try:
246
+ data = json.loads(json_str)
247
+
248
+ # Extract the required metrics with default values
249
+ metrics = {
250
+ "quality_rating": float(data.get("quality_rating", 0)),
251
+ "accuracy": float(data.get("accuracy", 0.0)),
252
+ "completeness": float(data.get("completeness", 0.0)),
253
+ "best_practices_alignment": float(data.get("best_practices_alignment", 0.0))
254
+ }
255
+
256
+ return metrics
257
+ except json.JSONDecodeError as je:
258
+ print(f"JSON decode error: {je}")
259
+ return None
260
+ else:
261
+ print("No JSON found in validation text")
262
+ return None
263
  except Exception as e:
264
  print(f"Error extracting metrics: {e}")
265
  return None