Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,14 +45,19 @@ def analyze_image(image, prompt):
|
|
| 45 |
with torch.no_grad():
|
| 46 |
output = model.generate(**inputs, max_new_tokens=100)
|
| 47 |
print(processor.decode(output[0]))
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
default_prompt = """Analyze this image and determine if it contains a data logger. A data logger is typically a small, black electronic device used to monitor and record data over time, such as voltage, temperature, or current, via external sensors.
|
| 58 |
|
|
|
|
| 45 |
with torch.no_grad():
|
| 46 |
output = model.generate(**inputs, max_new_tokens=100)
|
| 47 |
print(processor.decode(output[0]))
|
| 48 |
+
full_response = processor.decode(output[0])
|
| 49 |
+
|
| 50 |
|
| 51 |
+
json_match = re.search(r'\{.*\}', full_response, re.DOTALL)
|
| 52 |
+
if json_match:
|
| 53 |
+
json_str = json_match.group(0)
|
| 54 |
+
try:
|
| 55 |
+
return json.loads(json_str)
|
| 56 |
+
except json.JSONDecodeError:
|
| 57 |
+
return {"error": "Failed to parse model output as JSON", "raw_output": json_str}
|
| 58 |
+
else:
|
| 59 |
+
return {"error": "No JSON found in the response", "raw_output": full_response}
|
| 60 |
+
|
| 61 |
|
| 62 |
default_prompt = """Analyze this image and determine if it contains a data logger. A data logger is typically a small, black electronic device used to monitor and record data over time, such as voltage, temperature, or current, via external sensors.
|
| 63 |
|