Rekham1110 commited on
Commit
5d7cefc
·
verified ·
1 Parent(s): 51ba804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -105
app.py CHANGED
@@ -145,11 +145,11 @@ def process_image(images, project_name, project_type):
145
  try:
146
  if not images:
147
  logging.warning("No images uploaded")
148
- return "<p style='color: red;'>Error: Please upload at least one image.</p>", "Pending", "", "", 0
149
 
150
  if not project_name:
151
  logging.warning("Project name missing")
152
- return "<p style='color: red;'>Error: Project Name is required.</p>", "Pending", "", "", 0
153
 
154
  results = []
155
  image_urls = []
@@ -219,7 +219,7 @@ def process_image(images, project_name, project_type):
219
 
220
  if not results:
221
  logging.warning("No images processed successfully")
222
- return "<p style='color: red;'>Error: No images were successfully processed.</p>", "Failure", "", "", 0
223
 
224
  total_percent_complete = round(sum(all_percentages) / len(all_percentages), 2)
225
  all_milestones_str = ", ".join(all_milestones)
@@ -250,7 +250,7 @@ def process_image(images, project_name, project_type):
250
  logging.info(f"Salesforce record created for project {project_name}")
251
  except Exception as e:
252
  logging.error(f"Failed to create Salesforce record: {str(e)}")
253
- return f"<p style='color: red;'>Error: Failed to update Salesforce - {str(e)}</p>", "Failure", "", "", 0
254
 
255
  # Format output
256
  output_html = "<div class='output'>"
@@ -271,107 +271,8 @@ def process_image(images, project_name, project_type):
271
  output_html += f"<p><strong>Note:</strong> Only the image with the highest completion percentage is stored in Salesforce.</p>"
272
  output_html += "</div>"
273
 
274
- return output_html, "Success", "", f"Max Confidence: {max_confidence}", f"{total_percent_complete}%"
275
 
276
  except Exception as e:
277
  logging.error(f"Processing failed: {str(e)}")
278
- return f"<p style='color: red;'>Error: {str(e)}</p>", "Failure", "", "", "0%"
279
-
280
- # Gradio UI
281
- with gr.Blocks(css="""
282
- .gradio-container {
283
- background-color: #f9f9f9;
284
- font-family: 'Roboto', sans-serif;
285
- padding: 20px;
286
- }
287
- .title {
288
- color: #34495e;
289
- font-size: 30px;
290
- text-align: center;
291
- font-weight: bold;
292
- margin-bottom: 25px;
293
- text-transform: uppercase;
294
- }
295
- .gradio-row {
296
- text-align: center;
297
- max-width: 800px;
298
- margin: 0 auto;
299
- }
300
- .output {
301
- text-align: left;
302
- margin-top: 20px;
303
- padding: 30px;
304
- background-color: #ffffff;
305
- border-radius: 15px;
306
- box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
307
- max-width: 800px;
308
- margin-left: auto;
309
- margin-right: auto;
310
- }
311
- .output h3 {
312
- color: #2c3e50;
313
- font-size: 22px;
314
- font-weight: bold;
315
- margin-bottom: 20px;
316
- }
317
- .output ul {
318
- list-style-type: none;
319
- padding: 0;
320
- }
321
- .output li {
322
- padding: 14px;
323
- margin-bottom: 18px;
324
- border-radius: 10px;
325
- font-size: 16px;
326
- transition: background-color 0.3s ease;
327
- }
328
- .output li.success {
329
- background-color: #27ae60;
330
- color: white;
331
- }
332
- .output li.error {
333
- background-color: #e74c3c;
334
- color: white;
335
- }
336
- .button {
337
- display: block;
338
- margin: 25px auto;
339
- background-color: #3498db;
340
- color: white;
341
- border: none;
342
- padding: 15px 30px;
343
- border-radius: 10px;
344
- cursor: pointer;
345
- font-size: 18px;
346
- transition: background-color 0.3s ease;
347
- }
348
- .button:hover {
349
- background-color: #2980b9;
350
- }
351
- .input {
352
- text-align: center;
353
- max-width: 800px;
354
- margin: 0 auto;
355
- }
356
- """) as demo:
357
- gr.Markdown("<h1 class='title'>Construction Progress Analyzer</h1>")
358
- with gr.Row():
359
- project_type_input = gr.Dropdown(label="Project Type", choices=["House", "Apartment"], value="House")
360
- project_name_input = gr.Textbox(label="Project Name (Required)", placeholder="e.g. Project_12345")
361
-
362
- image_input = gr.File(
363
- file_count="multiple",
364
- file_types=["image"],
365
- label="Upload Construction Site Photos (JPG/PNG, ≤20MB each)"
366
- )
367
- submit_button = gr.Button("Process Images")
368
- output_html = gr.HTML(label="Result")
369
-
370
- submit_button.click(
371
- fn=process_image,
372
- inputs=[image_input, project_name_input, project_type_input],
373
- outputs=[output_html]
374
- )
375
-
376
- logging.info("Launching Gradio interface")
377
- demo.launch()
 
145
  try:
146
  if not images:
147
  logging.warning("No images uploaded")
148
+ return "<p style='color: red;'>Error: Please upload at least one image.</p>", "Pending", "", "", ""
149
 
150
  if not project_name:
151
  logging.warning("Project name missing")
152
+ return "<p style='color: red;'>Error: Project Name is required.</p>", "Pending", "", "", ""
153
 
154
  results = []
155
  image_urls = []
 
219
 
220
  if not results:
221
  logging.warning("No images processed successfully")
222
+ return "<p style='color: red;'>Error: No images were successfully processed.</p>", "Failure", "", "", ""
223
 
224
  total_percent_complete = round(sum(all_percentages) / len(all_percentages), 2)
225
  all_milestones_str = ", ".join(all_milestones)
 
250
  logging.info(f"Salesforce record created for project {project_name}")
251
  except Exception as e:
252
  logging.error(f"Failed to create Salesforce record: {str(e)}")
253
+ return f"<p style='color: red;'>Error: Failed to update Salesforce - {str(e)}</p>", "Failure", "", "", ""
254
 
255
  # Format output
256
  output_html = "<div class='output'>"
 
271
  output_html += f"<p><strong>Note:</strong> Only the image with the highest completion percentage is stored in Salesforce.</p>"
272
  output_html += "</div>"
273
 
274
+ return output_html, "Success", "", "", ""
275
 
276
  except Exception as e:
277
  logging.error(f"Processing failed: {str(e)}")
278
+ return f"<p style='color: red;'>Error: {str(e)}</p>", "Failure", "", "", ""