vasanthi8134 commited on
Commit
ffd5144
·
verified ·
1 Parent(s): 56047a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -40,6 +40,7 @@ def classify_with_openai(image_path):
40
  "Classify the pet in this image. "
41
  f"Choose exactly one label from this list: {CLASS_LABELS}. "
42
  'Return valid JSON with keys: "label", "confidence", "reasoning". '
 
43
  "Confidence must be a number between 0 and 1."
44
  )
45
 
@@ -61,8 +62,17 @@ def classify_with_openai(image_path):
61
  ],
62
  )
63
 
 
 
 
 
 
 
 
 
 
64
  try:
65
- return json.loads(response.output_text)
66
  except Exception:
67
  return {"raw_response": response.output_text}
68
 
 
40
  "Classify the pet in this image. "
41
  f"Choose exactly one label from this list: {CLASS_LABELS}. "
42
  'Return valid JSON with keys: "label", "confidence", "reasoning". '
43
+ "Do not use markdown code fences. "
44
  "Confidence must be a number between 0 and 1."
45
  )
46
 
 
62
  ],
63
  )
64
 
65
+ text = response.output_text.strip()
66
+
67
+ if text.startswith("```json"):
68
+ text = text[len("```json"):].strip()
69
+ if text.startswith("```"):
70
+ text = text[len("```"):].strip()
71
+ if text.endswith("```"):
72
+ text = text[:-3].strip()
73
+
74
  try:
75
+ return json.loads(text)
76
  except Exception:
77
  return {"raw_response": response.output_text}
78