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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -38,7 +38,7 @@ def encode_image(image):
38
  def analyze_construction_image(image):
39
  if image is None:
40
  logger.warning("No image provided")
41
- return [(None, "Error: No image uploaded")], "Error: No image uploaded"
42
 
43
  try:
44
  logger.info("Starting image analysis")
@@ -80,7 +80,7 @@ def analyze_construction_image(image):
80
 
81
  if not result:
82
  logger.warning("Received empty response from API")
83
- return [(None, "Error: Received empty response from API")], "Error: Received empty response from API"
84
 
85
  # Parse the result
86
  analysis_text = "Safety and Hazard Analysis of the Construction Site Image:\n\n"
@@ -88,7 +88,7 @@ def analyze_construction_image(image):
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.")], "Error: Unable to parse the response"
92
 
93
  for category in categories:
94
  lines = category.split("\n")
@@ -107,12 +107,12 @@ def analyze_construction_image(image):
107
  analysis_text += "\n"
108
 
109
  logger.info("Analysis completed successfully")
110
- return [(None, analysis_text)], "" # Return as a list with a single tuple
111
  except Exception as e:
112
  logger.error(f"Error during image analysis: {str(e)}")
113
  logger.error(traceback.format_exc())
114
  error_message = f"Error during analysis: {str(e)}. Please try again or contact support if the issue persists."
115
- return [(None, error_message)], error_message
116
 
117
  def chat_about_image(message, chat_history):
118
  try:
 
38
  def analyze_construction_image(image):
39
  if image is None:
40
  logger.warning("No image provided")
41
+ return [(None, "Error: No image uploaded")]
42
 
43
  try:
44
  logger.info("Starting image analysis")
 
80
 
81
  if not result:
82
  logger.warning("Received empty response from API")
83
+ return [(None, "Error: Received empty response from API")]
84
 
85
  # Parse the result
86
  analysis_text = "Safety and Hazard Analysis of the Construction Site Image:\n\n"
 
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")
 
107
  analysis_text += "\n"
108
 
109
  logger.info("Analysis completed successfully")
110
+ return [(None, analysis_text)]
111
  except Exception as e:
112
  logger.error(f"Error during image analysis: {str(e)}")
113
  logger.error(traceback.format_exc())
114
  error_message = f"Error during analysis: {str(e)}. Please try again or contact support if the issue persists."
115
+ return [(None, error_message)]
116
 
117
  def chat_about_image(message, chat_history):
118
  try: