Update app.py
Browse files
app.py
CHANGED
|
@@ -67,7 +67,14 @@ def friendly_field_names(sf_record):
|
|
| 67 |
"Salesforce_Record_Id": "Salesforce Record Id",
|
| 68 |
"Salesforce_Error": "Salesforce Error"
|
| 69 |
}
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
try:
|
| 73 |
logger.info("Initializing PaddleOCR...")
|
|
@@ -146,7 +153,7 @@ def process_blueprint(image, blueprint_title, uploaded_by, structure_type,
|
|
| 146 |
|
| 147 |
open_cv_image = np.array(image)
|
| 148 |
open_cv_image = cv2.cvtColor(open_cv_image, cv2.COLOR_RGB2BGR)
|
| 149 |
-
gray = cv2.cvtColor(open_cv_image,
|
| 150 |
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
|
| 151 |
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, threshold=100, minLineLength=50, maxLineGap=10)
|
| 152 |
|
|
@@ -233,12 +240,12 @@ def process_blueprint(image, blueprint_title, uploaded_by, structure_type,
|
|
| 233 |
|
| 234 |
except Exception as e:
|
| 235 |
logger.error(f"Error processing blueprint: {str(e)}")
|
| 236 |
-
return
|
| 237 |
|
| 238 |
def gradio_process_file(image, blueprint_title, uploaded_by, structure_type,
|
| 239 |
slab_count, slab_area_per_slab, slab_thickness_ft, wall_height_ft):
|
| 240 |
if image is None:
|
| 241 |
-
return
|
| 242 |
try:
|
| 243 |
slab_count = int(slab_count)
|
| 244 |
slab_area_per_slab = float(slab_area_per_slab)
|
|
@@ -247,7 +254,7 @@ def gradio_process_file(image, blueprint_title, uploaded_by, structure_type,
|
|
| 247 |
if slab_count <= 0 or slab_area_per_slab <= 0 or slab_thickness_ft <= 0 or wall_height_ft <= 0:
|
| 248 |
raise ValueError("All inputs must be positive.")
|
| 249 |
except Exception as e:
|
| 250 |
-
return
|
| 251 |
|
| 252 |
return process_blueprint(image, blueprint_title, uploaded_by, structure_type,
|
| 253 |
slab_count, slab_area_per_slab, slab_thickness_ft, wall_height_ft)
|
|
@@ -265,7 +272,7 @@ interface = gr.Interface(
|
|
| 265 |
gr.Number(label="Wall Height (ft)", minimum=0.1, interactive=True)
|
| 266 |
],
|
| 267 |
outputs=[
|
| 268 |
-
gr.
|
| 269 |
gr.Textbox(label="Extracted Text from Blueprint")
|
| 270 |
],
|
| 271 |
title="Blueprint Material Estimator",
|
|
@@ -274,4 +281,4 @@ interface = gr.Interface(
|
|
| 274 |
|
| 275 |
if __name__ == "__main__":
|
| 276 |
logger.info("Launching app...")
|
| 277 |
-
interface.launch(share=False)
|
|
|
|
| 67 |
"Salesforce_Record_Id": "Salesforce Record Id",
|
| 68 |
"Salesforce_Error": "Salesforce Error"
|
| 69 |
}
|
| 70 |
+
# Convert dictionary to bulleted list string
|
| 71 |
+
bullet_points = []
|
| 72 |
+
for key, value in sf_record.items():
|
| 73 |
+
display_key = mapping.get(key, key)
|
| 74 |
+
# Skip Material_Summary__c as it's lengthy HTML
|
| 75 |
+
if key != "Material_Summary__c":
|
| 76 |
+
bullet_points.append(f"- {display_key}: {value}")
|
| 77 |
+
return "\n".join(bullet_points)
|
| 78 |
|
| 79 |
try:
|
| 80 |
logger.info("Initializing PaddleOCR...")
|
|
|
|
| 153 |
|
| 154 |
open_cv_image = np.array(image)
|
| 155 |
open_cv_image = cv2.cvtColor(open_cv_image, cv2.COLOR_RGB2BGR)
|
| 156 |
+
gray = cv2.cvtColor(open_cv_image, COLOR_BGR2GRAY)
|
| 157 |
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
|
| 158 |
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, threshold=100, minLineLength=50, maxLineGap=10)
|
| 159 |
|
|
|
|
| 240 |
|
| 241 |
except Exception as e:
|
| 242 |
logger.error(f"Error processing blueprint: {str(e)}")
|
| 243 |
+
return f"- Error: {str(e)}", None
|
| 244 |
|
| 245 |
def gradio_process_file(image, blueprint_title, uploaded_by, structure_type,
|
| 246 |
slab_count, slab_area_per_slab, slab_thickness_ft, wall_height_ft):
|
| 247 |
if image is None:
|
| 248 |
+
return "- Error: No image uploaded.", None
|
| 249 |
try:
|
| 250 |
slab_count = int(slab_count)
|
| 251 |
slab_area_per_slab = float(slab_area_per_slab)
|
|
|
|
| 254 |
if slab_count <= 0 or slab_area_per_slab <= 0 or slab_thickness_ft <= 0 or wall_height_ft <= 0:
|
| 255 |
raise ValueError("All inputs must be positive.")
|
| 256 |
except Exception as e:
|
| 257 |
+
return f"- Error: Invalid inputs: {str(e)}", None
|
| 258 |
|
| 259 |
return process_blueprint(image, blueprint_title, uploaded_by, structure_type,
|
| 260 |
slab_count, slab_area_per_slab, slab_thickness_ft, wall_height_ft)
|
|
|
|
| 272 |
gr.Number(label="Wall Height (ft)", minimum=0.1, interactive=True)
|
| 273 |
],
|
| 274 |
outputs=[
|
| 275 |
+
gr.Textbox(label="Blueprint Analysis Results"),
|
| 276 |
gr.Textbox(label="Extracted Text from Blueprint")
|
| 277 |
],
|
| 278 |
title="Blueprint Material Estimator",
|
|
|
|
| 281 |
|
| 282 |
if __name__ == "__main__":
|
| 283 |
logger.info("Launching app...")
|
| 284 |
+
interface.launch(share=False)
|