capradeepgujaran commited on
Commit
beb288f
·
verified ·
1 Parent(s): 7e0ce73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
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
- if not categories:
90
- logger.warning("No categories found in the response")
91
- return [(None, "Error: Unable to parse the response. No categories found.")]
92
-
93
- for category in categories:
94
- lines = category.split("\n")
95
- category_name = lines[0].split(":")[1].strip() if ":" in lines[0] else lines[0].strip()
96
- analysis_text += f"Category: {category_name}\n"
97
-
98
- description = next((line.split("Description:")[1].strip() for line in lines if "Description:" in line), "N/A")
99
- hazard = next((line.split("Hazard:")[1].strip() for line in lines if "Hazard:" in line), "N/A")
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)]