capradeepgujaran
commited on
Commit
•
e2d89e8
1
Parent(s):
8fc888c
Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ def analyze_construction_image(image):
|
|
50 |
"content": [
|
51 |
{
|
52 |
"type": "text",
|
53 |
-
"text": "Analyze this construction site image. Identify any issues or snags, categorize them, provide a detailed description, and suggest steps
|
54 |
},
|
55 |
{
|
56 |
"type": "image_url",
|
@@ -85,15 +85,23 @@ def analyze_construction_image(image):
|
|
85 |
logger.error("Failed to parse API response as JSON")
|
86 |
return [(None, "Error: Invalid response format")]
|
87 |
|
88 |
-
snag_category = parsed_result.get('snag_category', 'N/A')
|
89 |
-
snag_description = parsed_result.get('snag_description', 'N/A')
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
logger.info("Analysis completed successfully")
|
93 |
|
94 |
# Initialize chat history with analysis results
|
95 |
chat_history = [
|
96 |
-
(None, f"Image Analysis Results:\n\nSnag Category: {snag_category}\n\nSnag Description: {snag_description}\n\nSteps to Desnag:\n{
|
97 |
]
|
98 |
|
99 |
return chat_history
|
|
|
50 |
"content": [
|
51 |
{
|
52 |
"type": "text",
|
53 |
+
"text": "Analyze this construction site image. Identify any issues or snags, categorize them, provide a detailed description, and suggest steps to resolve them. Format your response as a JSON object with keys 'snag_category', 'snag_description', and 'desnag_steps' (as an array)."
|
54 |
},
|
55 |
{
|
56 |
"type": "image_url",
|
|
|
85 |
logger.error("Failed to parse API response as JSON")
|
86 |
return [(None, "Error: Invalid response format")]
|
87 |
|
88 |
+
snag_category = str(parsed_result.get('snag_category', 'N/A'))
|
89 |
+
snag_description = str(parsed_result.get('snag_description', 'N/A'))
|
90 |
+
|
91 |
+
# Ensure desnag_steps is a list of strings
|
92 |
+
desnag_steps = parsed_result.get('desnag_steps', ['N/A'])
|
93 |
+
if not isinstance(desnag_steps, list):
|
94 |
+
desnag_steps = [str(desnag_steps)]
|
95 |
+
else:
|
96 |
+
desnag_steps = [str(step) for step in desnag_steps]
|
97 |
+
|
98 |
+
desnag_steps_str = '\n'.join(desnag_steps)
|
99 |
|
100 |
logger.info("Analysis completed successfully")
|
101 |
|
102 |
# Initialize chat history with analysis results
|
103 |
chat_history = [
|
104 |
+
(None, f"Image Analysis Results:\n\nSnag Category: {snag_category}\n\nSnag Description: {snag_description}\n\nSteps to Desnag:\n{desnag_steps_str}")
|
105 |
]
|
106 |
|
107 |
return chat_history
|