chandra7799 commited on
Commit
89aed7b
·
verified ·
1 Parent(s): 3d96d13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -41,7 +41,7 @@ local_timezone = pytz.timezone("Asia/Kolkata")
41
  def process_image(images, project_name):
42
  try:
43
  if not images or len(images) == 0:
44
- return "Error: Please upload at least one image to proceed.", "Pending", "", 0
45
 
46
  # Process each image
47
  milestones = []
@@ -49,9 +49,9 @@ def process_image(images, project_name):
49
  img = Image.open(image)
50
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
51
  if image_size_mb > 20:
52
- return "Error: One or more images exceed 20MB.", "Failure", "", 0
53
  if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
54
- return "Error: Only JPG/PNG images are supported.", "Failure", "", 0
55
 
56
  # Save image to public folder temporarily before uploading to Salesforce
57
  upload_dir = "public_uploads"
@@ -78,7 +78,7 @@ def process_image(images, project_name):
78
  content_version_id = content_version_result['id']
79
  file_url = f"https://sathkruthatechsolutionspri8-dev-ed.develop.lightning.force.com/{content_version_id}"
80
  except Exception as e:
81
- return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", 0
82
 
83
  # Mock AI model to detect milestone based on image content
84
  img_bytes = img.tobytes()
@@ -224,12 +224,12 @@ def process_image(images, project_name):
224
  try:
225
  sf.Construction__c.create(record)
226
  except Exception as e:
227
- return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", 0
228
 
229
- return result_html, "Success", final_milestone, f"{percent_complete}%"
230
 
231
  except Exception as e:
232
- return f"Error: {str(e)}", "Failure", "", "0%"
233
 
234
  # Gradio UI with enhanced styling
235
  with gr.Blocks(css="""
@@ -292,12 +292,13 @@ with gr.Blocks(css="""
292
  output_html = gr.HTML(label="Result") # Changed to HTML for richer output
293
  upload_status = gr.Textbox(label="Upload Status")
294
  milestone = gr.Textbox(label="Detected Milestone")
 
295
  progress = gr.Textbox(label="Completion Percentage", interactive=False)
296
 
297
  submit_button.click(
298
  fn=process_image,
299
  inputs=[image_input, project_name_input],
300
- outputs=[output_html, upload_status, milestone, progress]
301
  )
302
 
303
  demo.launch(share=True)
 
41
  def process_image(images, project_name):
42
  try:
43
  if not images or len(images) == 0:
44
+ return "Error: Please upload at least one image to proceed.", "Pending", "", "", 0
45
 
46
  # Process each image
47
  milestones = []
 
49
  img = Image.open(image)
50
  image_size_mb = os.path.getsize(image) / (1024 * 1024)
51
  if image_size_mb > 20:
52
+ return "Error: One or more images exceed 20MB.", "Failure", "", "", 0
53
  if not str(image).lower().endswith(('.jpg', '.jpeg', '.png')):
54
+ return "Error: Only JPG/PNG images are supported.", "Failure", "", "", 0
55
 
56
  # Save image to public folder temporarily before uploading to Salesforce
57
  upload_dir = "public_uploads"
 
78
  content_version_id = content_version_result['id']
79
  file_url = f"https://sathkruthatechsolutionspri8-dev-ed.develop.lightning.force.com/{content_version_id}"
80
  except Exception as e:
81
+ return f"Error: Failed to upload image to Salesforce - {str(e)}", "Failure", "", "", 0
82
 
83
  # Mock AI model to detect milestone based on image content
84
  img_bytes = img.tobytes()
 
224
  try:
225
  sf.Construction__c.create(record)
226
  except Exception as e:
227
+ return f"Error: Failed to update Salesforce - {str(e)}", "Failure", "", "", 0
228
 
229
+ return result_html, "Success", final_milestone, "", f"{percent_complete}%"
230
 
231
  except Exception as e:
232
+ return f"Error: {str(e)}", "Failure", "", "", "0%"
233
 
234
  # Gradio UI with enhanced styling
235
  with gr.Blocks(css="""
 
292
  output_html = gr.HTML(label="Result") # Changed to HTML for richer output
293
  upload_status = gr.Textbox(label="Upload Status")
294
  milestone = gr.Textbox(label="Detected Milestone")
295
+ confidence = gr.Textbox(label="Confidence Score") # Kept for compatibility, but unused
296
  progress = gr.Textbox(label="Completion Percentage", interactive=False)
297
 
298
  submit_button.click(
299
  fn=process_image,
300
  inputs=[image_input, project_name_input],
301
+ outputs=[output_html, upload_status, milestone, confidence, progress]
302
  )
303
 
304
  demo.launch(share=True)