Update app.py
Browse files
app.py
CHANGED
|
@@ -73,11 +73,14 @@ def analyze_image(image):
|
|
| 73 |
"text": """Your task is to determine if the image is surprising or not surprising.
|
| 74 |
if the image is surprising, determine which element, figure or object in the image is making the image surprising and write it only in one sentence with no more then 6 words, otherwise, write 'NA'.
|
| 75 |
Also rate how surprising the image is on a scale of 1-5, where 1 is not surprising at all and 5 is highly surprising.
|
|
|
|
| 76 |
Provide the response as a JSON with the following structure:
|
| 77 |
{
|
| 78 |
"label": "[surprising OR not surprising]",
|
| 79 |
"element": "[element]",
|
| 80 |
-
"rating": [1-5]
|
|
|
|
|
|
|
| 81 |
}"""
|
| 82 |
},
|
| 83 |
{
|
|
@@ -250,13 +253,13 @@ def process_image_detection(image, target_label, surprise_rating):
|
|
| 250 |
ax.add_patch(rect)
|
| 251 |
|
| 252 |
# Only add the probability score
|
| 253 |
-
plt.text(
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
)
|
| 260 |
|
| 261 |
plt.axis('off')
|
| 262 |
|
|
@@ -354,8 +357,10 @@ def process_and_analyze(image):
|
|
| 354 |
analysis_text = (
|
| 355 |
f"Label: {response_data['label']}\n"
|
| 356 |
f"Element: {response_data['element']}\n"
|
| 357 |
-
f"Rating: {response_data['rating']}/5"
|
| 358 |
-
|
|
|
|
|
|
|
| 359 |
return result_image, analysis_text
|
| 360 |
except Exception as detection_error:
|
| 361 |
print(f"Detection error details: {str(detection_error)}") # Debug print
|
|
|
|
| 73 |
"text": """Your task is to determine if the image is surprising or not surprising.
|
| 74 |
if the image is surprising, determine which element, figure or object in the image is making the image surprising and write it only in one sentence with no more then 6 words, otherwise, write 'NA'.
|
| 75 |
Also rate how surprising the image is on a scale of 1-5, where 1 is not surprising at all and 5 is highly surprising.
|
| 76 |
+
Additionally, write one sentence about what would be expected in this scene, and one sentence about what is unexpected.
|
| 77 |
Provide the response as a JSON with the following structure:
|
| 78 |
{
|
| 79 |
"label": "[surprising OR not surprising]",
|
| 80 |
"element": "[element]",
|
| 81 |
+
"rating": [1-5],
|
| 82 |
+
"expected": "[one sentence about what would be expected]",
|
| 83 |
+
"unexpected": "[one sentence about what is unexpected]"
|
| 84 |
}"""
|
| 85 |
},
|
| 86 |
{
|
|
|
|
| 253 |
ax.add_patch(rect)
|
| 254 |
|
| 255 |
# Only add the probability score
|
| 256 |
+
#plt.text(
|
| 257 |
+
# box[0], box[1] - base_fontsize,
|
| 258 |
+
# f'{max_score:.2f}',
|
| 259 |
+
# color='red',
|
| 260 |
+
# fontsize=base_fontsize,
|
| 261 |
+
# fontweight='bold'
|
| 262 |
+
#)
|
| 263 |
|
| 264 |
plt.axis('off')
|
| 265 |
|
|
|
|
| 357 |
analysis_text = (
|
| 358 |
f"Label: {response_data['label']}\n"
|
| 359 |
f"Element: {response_data['element']}\n"
|
| 360 |
+
f"Rating: {response_data['rating']}/5\n"
|
| 361 |
+
f"Expected: {response_data['expected']}\n"
|
| 362 |
+
f"Unexpected: {response_data['unexpected']}"
|
| 363 |
+
)
|
| 364 |
return result_image, analysis_text
|
| 365 |
except Exception as detection_error:
|
| 366 |
print(f"Detection error details: {str(detection_error)}") # Debug print
|