Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,27 +84,18 @@ def analyze_construction_image(image):
|
|
| 84 |
|
| 85 |
# Parse the result
|
| 86 |
analysis_text = "Safety and Hazard Analysis of the Construction Site Image:\n\n"
|
| 87 |
-
categories = result.split("Category")[1:] # Split by categories
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
resolution_steps = [line.strip() for line in lines if line.strip().startswith("*")]
|
| 101 |
-
|
| 102 |
-
analysis_text += f"Description: {description}\n"
|
| 103 |
-
analysis_text += f"Hazard: {hazard}\n"
|
| 104 |
-
analysis_text += "Resolution Steps:\n"
|
| 105 |
-
for step in resolution_steps:
|
| 106 |
-
analysis_text += f"{step}\n"
|
| 107 |
-
analysis_text += "\n"
|
| 108 |
|
| 109 |
logger.info("Analysis completed successfully")
|
| 110 |
return [(None, analysis_text)]
|
|
|
|
| 84 |
|
| 85 |
# Parse the result
|
| 86 |
analysis_text = "Safety and Hazard Analysis of the Construction Site Image:\n\n"
|
|
|
|
| 87 |
|
| 88 |
+
sections = ["Hazard Identification", "Categorization", "Detailed Description", "Resolution Steps"]
|
| 89 |
+
for section in sections:
|
| 90 |
+
start = result.find(section)
|
| 91 |
+
if start != -1:
|
| 92 |
+
end = result.find(next((s for s in sections if s != section and result.find(s) > start), None))
|
| 93 |
+
content = result[start:end if end != -1 else None].strip()
|
| 94 |
+
analysis_text += f"{content}\n\n"
|
| 95 |
+
|
| 96 |
+
if analysis_text == "Safety and Hazard Analysis of the Construction Site Image:\n\n":
|
| 97 |
+
logger.warning("No sections found in the response")
|
| 98 |
+
return [(None, "Error: Unable to parse the response. No sections found.")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
logger.info("Analysis completed successfully")
|
| 101 |
return [(None, analysis_text)]
|