capradeepgujaran commited on
Commit
64a9ffc
·
verified ·
1 Parent(s): 337ada4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
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 "Error: No image uploaded", "", "", []
42
 
43
  try:
44
  logger.info("Starting image analysis")
@@ -83,7 +83,7 @@ def analyze_construction_image(image):
83
  parsed_result = json.loads(result)
84
  except json.JSONDecodeError:
85
  logger.error("Failed to parse API response as JSON")
86
- return "Error: Invalid response format", "", "", []
87
 
88
  snag_category = parsed_result.get('snag_category', 'N/A')
89
  snag_description = parsed_result.get('snag_description', 'N/A')
@@ -93,13 +93,13 @@ def analyze_construction_image(image):
93
 
94
  # Initialize chat history with analysis results
95
  chat_history = [
96
- (None, f"Snag Category: {snag_category}\n\nSnag Description: {snag_description}\n\nSteps to Desnag:\n{desnag_steps}")
97
  ]
98
 
99
- return snag_category, snag_description, desnag_steps, chat_history
100
  except Exception as e:
101
  logger.error(f"Error during image analysis: {str(e)}")
102
- return f"Error: {str(e)}", "", "", []
103
 
104
  def chat_about_image(message, chat_history):
105
  try:
@@ -120,7 +120,7 @@ def chat_about_image(message, chat_history):
120
 
121
  # Make API call
122
  completion = client.chat.completions.create(
123
- model="llama-3.2-90b-vision-preview", # Using the chat model here
124
  messages=messages,
125
  temperature=0.7,
126
  max_tokens=500,
@@ -145,18 +145,15 @@ with gr.Blocks() as iface:
145
  image_input = gr.Image(type="pil", label="Upload Construction Image")
146
  analyze_button = gr.Button("Analyze Image")
147
  with gr.Column(scale=2):
148
- snag_category = gr.Textbox(label="Snag Category")
149
- snag_description = gr.Textbox(label="Snag Description")
150
- desnag_steps = gr.Textbox(label="Steps to Desnag")
151
 
152
- chatbot = gr.Chatbot(label="Chat about the Image")
153
  msg = gr.Textbox(label="Ask a question about the image")
154
- clear = gr.Button("Clear")
155
 
156
  analyze_button.click(
157
  analyze_construction_image,
158
  inputs=[image_input],
159
- outputs=[snag_category, snag_description, desnag_steps, chatbot]
160
  )
161
 
162
  msg.submit(chat_about_image, [msg, chatbot], [msg, chatbot])
 
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")
 
83
  parsed_result = json.loads(result)
84
  except json.JSONDecodeError:
85
  logger.error("Failed to parse API response as JSON")
86
+ return [(None, "Error: Invalid response format")]
87
 
88
  snag_category = parsed_result.get('snag_category', 'N/A')
89
  snag_description = parsed_result.get('snag_description', 'N/A')
 
93
 
94
  # Initialize chat history with analysis results
95
  chat_history = [
96
+ (None, f"Image Analysis Results:\n\nSnag Category: {snag_category}\n\nSnag Description: {snag_description}\n\nSteps to Desnag:\n{desnag_steps}")
97
  ]
98
 
99
+ return chat_history
100
  except Exception as e:
101
  logger.error(f"Error during image analysis: {str(e)}")
102
+ return [(None, f"Error: {str(e)}")]
103
 
104
  def chat_about_image(message, chat_history):
105
  try:
 
120
 
121
  # Make API call
122
  completion = client.chat.completions.create(
123
+ model="llama-3.2-90b-vision-preview",
124
  messages=messages,
125
  temperature=0.7,
126
  max_tokens=500,
 
145
  image_input = gr.Image(type="pil", label="Upload Construction Image")
146
  analyze_button = gr.Button("Analyze Image")
147
  with gr.Column(scale=2):
148
+ chatbot = gr.Chatbot(label="Analysis Results and Chat")
 
 
149
 
 
150
  msg = gr.Textbox(label="Ask a question about the image")
151
+ clear = gr.Button("Clear Chat")
152
 
153
  analyze_button.click(
154
  analyze_construction_image,
155
  inputs=[image_input],
156
+ outputs=[chatbot]
157
  )
158
 
159
  msg.submit(chat_about_image, [msg, chatbot], [msg, chatbot])