Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|