capradeepgujaran
commited on
Commit
•
8a33d7b
1
Parent(s):
5932cce
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 safety issues or hazards, categorize them, provide a detailed description, and suggest steps to resolve them. Format your response as a
|
54 |
},
|
55 |
{
|
56 |
"type": "image_url",
|
@@ -70,7 +70,6 @@ def analyze_construction_image(image):
|
|
70 |
max_tokens=1000,
|
71 |
top_p=1,
|
72 |
stream=False,
|
73 |
-
response_format={"type": "json_object"},
|
74 |
stop=None
|
75 |
)
|
76 |
|
@@ -78,23 +77,21 @@ def analyze_construction_image(image):
|
|
78 |
result = completion.choices[0].message.content
|
79 |
logger.debug(f"Raw API response: {result}")
|
80 |
|
81 |
-
# Parse the result
|
82 |
-
try:
|
83 |
-
parsed_result = json.loads(result)
|
84 |
-
issues = parsed_result.get('issues', [])
|
85 |
-
except json.JSONDecodeError:
|
86 |
-
logger.error("Failed to parse API response as JSON")
|
87 |
-
return [(None, "Error: Invalid response format")]
|
88 |
-
|
89 |
-
# Format the analysis results
|
90 |
analysis_text = "Image Analysis Results:\n\n"
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
logger.info("Analysis completed successfully")
|
100 |
return [(None, analysis_text)]
|
|
|
50 |
"content": [
|
51 |
{
|
52 |
"type": "text",
|
53 |
+
"text": "Analyze this construction site image. Identify any safety issues or hazards, categorize them, provide a detailed description, and suggest steps to resolve them. Format your response as a structured analysis with clear categories, descriptions, and resolution steps."
|
54 |
},
|
55 |
{
|
56 |
"type": "image_url",
|
|
|
70 |
max_tokens=1000,
|
71 |
top_p=1,
|
72 |
stream=False,
|
|
|
73 |
stop=None
|
74 |
)
|
75 |
|
|
|
77 |
result = completion.choices[0].message.content
|
78 |
logger.debug(f"Raw API response: {result}")
|
79 |
|
80 |
+
# Parse the result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
analysis_text = "Image Analysis Results:\n\n"
|
82 |
+
categories = result.split("Category: ")[1:] # Split by categories
|
83 |
+
for category in categories:
|
84 |
+
lines = category.split("\n")
|
85 |
+
category_name = lines[0].strip()
|
86 |
+
analysis_text += f"Category: {category_name}\n"
|
87 |
+
|
88 |
+
description_start = category.find("Description: ") + len("Description: ")
|
89 |
+
description_end = category.find("Resolution Steps:")
|
90 |
+
description = category[description_start:description_end].strip()
|
91 |
+
analysis_text += f"Description: {description}\n"
|
92 |
+
|
93 |
+
resolution_steps = "".join(lines[lines.index("Resolution Steps:") + 1:]).replace("* ", "").replace("\n", "")
|
94 |
+
analysis_text += f"Resolution Steps:\n{resolution_steps}\n\n"
|
95 |
|
96 |
logger.info("Analysis completed successfully")
|
97 |
return [(None, analysis_text)]
|