danielrosehill Claude commited on
Commit
ea95d12
·
1 Parent(s): 932db80

Fix annotation mode and HuggingFace push issues

Browse files

- Fix README short_description to be under 60 chars (HF requirement)
- Improve annotation mode error handling and visibility
- Add clear error messages when AI doesn't provide annotations
- Add annotation count feedback when successful
- Update UI description to clarify numbered markers are drawn
- Add detailed error messages for annotation parsing failures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +45 -6
README.md CHANGED
@@ -7,7 +7,7 @@ sdk: gradio
7
  sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
- short_description: Professional satellite imagery intelligence analysis powered by Claude
11
  ---
12
 
13
  # 🛰️ SATINT Analyst
 
7
  sdk_version: 5.49.1
8
  app_file: app.py
9
  pinned: false
10
+ short_description: Professional satellite imagery intelligence analysis
11
  ---
12
 
13
  # 🛰️ SATINT Analyst
app.py CHANGED
@@ -207,6 +207,23 @@ Remember: The annotations will be numbered automatically in the order you list t
207
  annotated_image = image
208
 
209
  # Look for ANNOTATIONS: section
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  if "ANNOTATIONS:" in analysis_text:
211
  # Extract the JSON part
212
  parts = analysis_text.split("ANNOTATIONS:")
@@ -223,23 +240,45 @@ Remember: The annotations will be numbered automatically in the order you list t
223
  annotations = json.loads(json_str)
224
 
225
  # Draw annotations on image
226
- if annotations:
227
  annotated_image = draw_annotations(image, annotations)
228
 
 
 
 
229
  # Clean up the analysis text to remove JSON section
230
  # Keep only the analysis part
231
  if "ANALYSIS:" in analysis_text:
232
- analysis_text = "ANALYSIS:\n" + analysis_text.split("ANALYSIS:")[1].strip()
233
  elif "SECTION 2" in analysis_text:
234
- analysis_text = analysis_text.split("SECTION 2")[1].strip()
235
  if analysis_text.startswith("- ANALYSIS:"):
236
  analysis_text = analysis_text[12:].strip()
 
 
 
237
 
238
  return analysis_text, annotated_image
239
 
240
  except Exception as e:
241
- # If annotation parsing fails, return original image with a note
242
- return f"[Note: Annotation parsing failed: {str(e)}]\n\n{analysis_text}", image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  else:
244
  return analysis_text, None
245
 
@@ -293,7 +332,7 @@ with gr.Blocks(title="SATINT Analyst - Satellite Imagery Analysis", theme=gr.the
293
  choices=["text_only", "annotated"],
294
  value="text_only",
295
  label="Analysis Mode",
296
- info="Text Only: Written analysis only | Annotated: Analysis with annotation descriptions"
297
  )
298
 
299
  analyze_btn = gr.Button("Analyze Imagery", variant="primary", size="lg")
 
207
  annotated_image = image
208
 
209
  # Look for ANNOTATIONS: section
210
+ if "ANNOTATIONS:" not in analysis_text:
211
+ # Model didn't provide annotations section
212
+ error_msg = """
213
+ ⚠️ **ANNOTATION MODE ERROR**
214
+
215
+ The AI model did not provide an ANNOTATIONS: section in its response.
216
+ This means it didn't follow the annotation format instructions.
217
+
218
+ Try again, or use Text Only mode for standard analysis.
219
+
220
+ ---
221
+
222
+ **AI Response:**
223
+
224
+ """
225
+ return error_msg + analysis_text, image
226
+
227
  if "ANNOTATIONS:" in analysis_text:
228
  # Extract the JSON part
229
  parts = analysis_text.split("ANNOTATIONS:")
 
240
  annotations = json.loads(json_str)
241
 
242
  # Draw annotations on image
243
+ if annotations and len(annotations) > 0:
244
  annotated_image = draw_annotations(image, annotations)
245
 
246
+ # Add annotation count to the analysis
247
+ annotation_count_msg = f"\n\n**✓ {len(annotations)} annotation(s) marked on image**\n\n"
248
+
249
  # Clean up the analysis text to remove JSON section
250
  # Keep only the analysis part
251
  if "ANALYSIS:" in analysis_text:
252
+ analysis_text = annotation_count_msg + "ANALYSIS:\n" + analysis_text.split("ANALYSIS:")[1].strip()
253
  elif "SECTION 2" in analysis_text:
254
+ analysis_text = annotation_count_msg + analysis_text.split("SECTION 2")[1].strip()
255
  if analysis_text.startswith("- ANALYSIS:"):
256
  analysis_text = analysis_text[12:].strip()
257
+ else:
258
+ # Annotations array was empty
259
+ analysis_text = "\n\n⚠️ **No annotations provided by AI model**\n\n" + analysis_text
260
 
261
  return analysis_text, annotated_image
262
 
263
  except Exception as e:
264
+ # If annotation parsing fails, return original image with a detailed note
265
+ error_msg = f"""
266
+ ⚠️ **ANNOTATION MODE ERROR**
267
+
268
+ The AI model's response could not be parsed for annotations. This usually happens when:
269
+ - The model doesn't return properly formatted JSON
270
+ - The ANNOTATIONS: section is missing or malformed
271
+ - The coordinate values are invalid
272
+
273
+ Error details: {str(e)}
274
+
275
+ ---
276
+
277
+ **Original AI Response:**
278
+
279
+ {analysis_text}
280
+ """
281
+ return error_msg, image
282
  else:
283
  return analysis_text, None
284
 
 
332
  choices=["text_only", "annotated"],
333
  value="text_only",
334
  label="Analysis Mode",
335
+ info="Text Only: Written analysis only | Annotated: Analysis with numbered markers drawn on the image"
336
  )
337
 
338
  analyze_btn = gr.Button("Analyze Imagery", variant="primary", size="lg")