capradeepgujaran commited on
Commit
8bded3a
1 Parent(s): 0d34f3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -77,22 +77,24 @@ def analyze_construction_image(images=None, video=None):
77
  logger.info("Starting analysis")
78
  results = []
79
 
 
 
 
 
 
 
80
  if images:
81
  for i, image_file in enumerate(images):
82
  image = Image.open(image_file.name)
83
  resized_image = resize_image(image)
84
  image_data_url = f"data:image/png;base64,{encode_image(resized_image)}"
85
  messages = [
86
- {
87
- "role": "system",
88
- "content": "You are an AI assistant specialized in analyzing images for safety issues. Your task is to first determine if the image shows a construction site. If it does, identify any safety issues or hazards, categorize them, provide a detailed description, and suggest steps to resolve them. If it's not a construction site, simply state that and briefly describe what you see in the image."
89
- },
90
  {
91
  "role": "user",
92
  "content": [
93
  {
94
  "type": "text",
95
- "text": f"Analyze this image (Image {i+1}/{len(images)}). First, determine if it's a construction site. If it is, explain the image in detail, focusing on safety aspects. If it's not, briefly describe what you see."
96
  },
97
  {
98
  "type": "image_url",
@@ -120,16 +122,12 @@ def analyze_construction_image(images=None, video=None):
120
  for i, frame in enumerate(frames):
121
  image_data_url = f"data:image/png;base64,{encode_image(frame)}"
122
  messages = [
123
- {
124
- "role": "system",
125
- "content": "You are an AI assistant specialized in analyzing video frames for safety issues. Your task is to first determine if the frame shows a construction site. If it does, identify any safety issues or hazards, categorize them, provide a detailed description, and suggest steps to resolve them. If it's not a construction site, simply state that and briefly describe what you see in the frame."
126
- },
127
  {
128
  "role": "user",
129
  "content": [
130
  {
131
  "type": "text",
132
- "text": f"Analyze this frame from a video (Frame {i+1}/{len(frames)}). First, determine if it's a construction site. If it is, explain what you observe, focusing on safety aspects. If it's not, briefly describe what you see."
133
  },
134
  {
135
  "type": "image_url",
@@ -158,6 +156,7 @@ def analyze_construction_image(images=None, video=None):
158
  logger.error(f"Error during analysis: {str(e)}")
159
  logger.error(traceback.format_exc())
160
  return [("Analysis error", f"Error during analysis: {str(e)}")]
 
161
 
162
  def chat_about_image(message, chat_history):
163
  try:
 
77
  logger.info("Starting analysis")
78
  results = []
79
 
80
+ instruction = ("You are an AI assistant specialized in analyzing images for safety issues. "
81
+ "Your task is to first determine if the image shows a construction site. "
82
+ "If it does, identify any safety issues or hazards, categorize them, provide a detailed description, "
83
+ "and suggest steps to resolve them. If it's not a construction site, simply state that and "
84
+ "briefly describe what you see in the image.")
85
+
86
  if images:
87
  for i, image_file in enumerate(images):
88
  image = Image.open(image_file.name)
89
  resized_image = resize_image(image)
90
  image_data_url = f"data:image/png;base64,{encode_image(resized_image)}"
91
  messages = [
 
 
 
 
92
  {
93
  "role": "user",
94
  "content": [
95
  {
96
  "type": "text",
97
+ "text": f"{instruction}\n\nAnalyze this image (Image {i+1}/{len(images)}). First, determine if it's a construction site. If it is, explain the image in detail, focusing on safety aspects. If it's not, briefly describe what you see."
98
  },
99
  {
100
  "type": "image_url",
 
122
  for i, frame in enumerate(frames):
123
  image_data_url = f"data:image/png;base64,{encode_image(frame)}"
124
  messages = [
 
 
 
 
125
  {
126
  "role": "user",
127
  "content": [
128
  {
129
  "type": "text",
130
+ "text": f"{instruction}\n\nAnalyze this frame from a video (Frame {i+1}/{len(frames)}). First, determine if it's a construction site. If it is, explain what you observe, focusing on safety aspects. If it's not, briefly describe what you see."
131
  },
132
  {
133
  "type": "image_url",
 
156
  logger.error(f"Error during analysis: {str(e)}")
157
  logger.error(traceback.format_exc())
158
  return [("Analysis error", f"Error during analysis: {str(e)}")]
159
+
160
 
161
  def chat_about_image(message, chat_history):
162
  try: