arjunanand13 commited on
Commit
ecc5376
·
verified ·
1 Parent(s): 6442033

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -42,17 +42,21 @@ def analyze_image(image, prompt):
42
  full_response = processor.decode(output[0])
43
  print("Full response:", full_response) # Debug print
44
 
45
- return full_response
46
- # try:
47
- # json_match = re.search(r'\{.*?\}', full_response, re.DOTALL)
48
- # if json_match:
49
- # json_str = json_match.group(0)
50
- # try:
51
- # return json.loads(json_str)
52
- # except json.JSONDecodeError as e:
53
- # return full_response
54
- # except Exception as e:
55
- # return full_response
 
 
 
 
56
 
57
 
58
  default_prompt = """Analyze this image and determine if it contains a data logger.
 
42
  full_response = processor.decode(output[0])
43
  print("Full response:", full_response) # Debug print
44
 
45
+ # return full_response
46
+ try:
47
+ json_match = re.search(r'\{.*?\}', full_response, re.DOTALL)
48
+ if json_match:
49
+ json_str = json_match.group(0)
50
+ try:
51
+ return json.loads(json_str)
52
+ except json.JSONDecodeError as e:
53
+ print(f"JSON decode error: {e}")
54
+ return {"error": "Invalid JSON in model output", "full_response": full_response}
55
+ else:
56
+ return {"error": "No JSON found in model output", "full_response": full_response}
57
+ except Exception as e:
58
+ print(f"Error in analyze_image: {e}")
59
+ return {"Full Response": str(e), "full_response": full_response}
60
 
61
 
62
  default_prompt = """Analyze this image and determine if it contains a data logger.