Skip to content

Commit b3e83e4

Browse files
committed
markdown test
1 parent 52227b5 commit b3e83e4

1 file changed

Lines changed: 38 additions & 51 deletions

File tree

evaluation_function/evaluation.py

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ def evaluation_function(
5555
feedback_start = time.time()
5656

5757
def append_feedback(title, text):
58-
feedback_items.append((title + "\n", text.strip() + "\n\n"))
58+
# Use standard Markdown for all feedback items
59+
# Title as level 2 heading, text as Markdown body
60+
markdown_title = f"## {title.strip()}\n"
61+
markdown_body = text.strip() + "\n\n"
62+
feedback_items.append((markdown_title, markdown_body))
5963

6064
def get_class_color(class_name):
6165
random.seed(hash(class_name) % 10000)
@@ -280,80 +284,55 @@ def analyze_images(images, draw_images=True):
280284
analysis_time = time.time() - analysis_start
281285

282286
if target_class:
283-
284287
append_feedback(
285288
"Target",
286-
f"--- Target ---\n"
287-
f"Target component: {target_class}",
289+
f"**Target component:** `{target_class}`",
288290
)
289291

290292
if response_detection and len(response) > 1:
291-
292293
origin = "center region" if overall_best_from_center else "full image"
293-
294294
overall_name = response[overall_best_image_idx].get(
295295
"name", f"image_{overall_best_image_idx}.jpg"
296296
)
297-
298297
append_feedback(
299298
"Overall Best",
300-
f"--- Best detection across all images ---\n"
301-
f"Image: {overall_name}\n"
302-
f"Detected Component: {response_detection} ({response_conf:.2f})\n"
303-
f"Source: {origin}\n\n",
299+
f"**Best detection across all images**\n\n"
300+
f"- **Image:** `{overall_name}`\n"
301+
f"- **Detected Component:** `{response_detection}`\n"
302+
f"- **Confidence:** `{response_conf:.2f}`\n"
303+
f"- **Source:** `{origin}`\n",
304304
)
305305

306306
upload_times = []
307307

308308
for idx, (img, detections, best_idx) in enumerate(annotated_images):
309-
310309
orig_name = response[idx].get("name", f"image_{idx}.jpg")
311-
312-
# set default link_html
313-
link_html = f"<b>Image: {orig_name}</b>"
314-
315310
info = per_image_best[idx]
316311
det = info["best_det"]
317-
318312
if det is None:
319-
320-
text = "No Component Detected"
321-
313+
text = "*No component detected.*"
322314
else:
323-
324315
_, _, _, _, conf, cls = det
325-
326316
origin = "center region" if info["chose_from_center"] else "full image"
327-
328317
text = (
329-
f"Detected Component: {cls}\n"
330-
f"Confidence: {conf:.2f}\n"
331-
f"Source: {origin}"
318+
f"- **Detected Component:** `{cls}`\n"
319+
f"- **Confidence:** `{conf:.2f}`\n"
320+
f"- **Source:** `{origin}`"
332321
)
333-
334-
combined = f"{link_html}\n{text}"
335-
336-
append_feedback(f"Image [{idx}]", f"--- Image [{idx}] ---\n" + combined)
337-
322+
append_feedback(
323+
f"Image [{idx}]",
324+
f"**Image:** `{orig_name}`\n\n{text}"
325+
)
338326
if draw_images and img is not None:
339-
340327
upload_start = time.time()
341-
342328
try:
343-
344329
url = upload_image(img, "eduvision")
345-
link_html = f'Image: <a href="{url}" target="_blank">{orig_name}\nLink To Annotation: {url}</a>'
346-
# add separate feedback for this uploaded annotated image
330+
# add separate feedback for this uploaded annotated image (Markdown image)
347331
append_feedback(f"Uploaded Image [{idx}]", f"![{orig_name}]({url})")
348-
349332
except:
350-
351-
link_html = f"<b>Image: {orig_name}</b>\nLink To Annotation: (upload failed)"
352-
333+
append_feedback(f"Uploaded Image [{idx}]", f"*Image upload failed for `{orig_name}`*")
353334
upload_times.append(time.time() - upload_start)
354-
355335
else:
356-
357336
upload_times.append(0.0)
358337

359338

@@ -365,14 +344,12 @@ def analyze_images(images, draw_images=True):
365344
total_time = time.time() - start_total
366345

367346
if params.get('debug', False):
368-
369-
# print response structure for debugging purposes
347+
# print response structure for debugging purposes
370348
try:
371-
# use repr to avoid issues with binary data
372-
append_feedback("DEBUG Response Structure:", f"--- DEBUG Response Structure ---\n{repr(response)}")
349+
append_feedback("DEBUG Response Structure", f"```python\n{repr(response)}\n```")
373350
print("DEBUG Response Structure:", repr(response))
374351
except Exception as e:
375-
append_feedback("Failed to print response structure", e)
352+
append_feedback("Failed to print response structure", f"{e}")
376353
print("Failed to print response structure", e)
377354

378355
# also check if YOLO can use GPU (torch.cuda availability)
@@ -389,17 +366,27 @@ def analyze_images(images, draw_images=True):
389366
except Exception:
390367
model_device = None
391368
print(f"DEBUG GPU Available: {gpu_available}, {model_device}")
392-
append_feedback("DEBUG GPU Available:", f"--- DEBUG GPU Available ---\n{gpu_available}, {model_device}")
369+
append_feedback("DEBUG GPU Available", f"- **GPU Available:** `{gpu_available}`\n- **Model Device:** `{model_device}`")
393370

394371
# include all annotated/uploaded images in debug output
395372
for idx, (img, _, _) in enumerate(annotated_images):
396373
if img is not None:
397-
# we previously uploaded each image and added a feedback entry in the loop above
398-
# but response urls correspond to originals; to be safe, show the response url here
399374
name = response[idx].get("name", f"image_{idx}.jpg")
400375
append_feedback(f'Uploaded Image [{idx}]', f'![{name}]({response[idx]["url"]})')
401376

402-
append_feedback("DEBUG Times:", f"--- DEBUG Times ---\nModel load: {model_load_time:.3f}s\nAvg image load: {avg_load_time:.3f}s\nAvg prediction: {avg_prediction_time:.3f}s\nAvg detection process: {avg_process_time:.3f}s\nAvg drawing: {avg_draw_time:.3f}s\nAvg upload: {avg_upload_time:.3f}s\nAnalysis: {analysis_time:.3f}s\nFeedback: {feedback_time:.3f}s\nTotal: {total_time:.3f}s")
377+
append_feedback(
378+
"DEBUG Times",
379+
f"| Step | Time (s) |\n|---|---|\n"
380+
f"| Model load | {model_load_time:.3f} |\n"
381+
f"| Avg image load | {avg_load_time:.3f} |\n"
382+
f"| Avg prediction | {avg_prediction_time:.3f} |\n"
383+
f"| Avg detection process | {avg_process_time:.3f} |\n"
384+
f"| Avg drawing | {avg_draw_time:.3f} |\n"
385+
f"| Avg upload | {avg_upload_time:.3f} |\n"
386+
f"| Analysis | {analysis_time:.3f} |\n"
387+
f"| Feedback | {feedback_time:.3f} |\n"
388+
f"| **Total** | **{total_time:.3f}** |\n"
389+
)
403390

404391
is_correct = response_detection == target_class and response_detection is not None
405392

0 commit comments

Comments
 (0)