malavikapradeep2001 commited on
Commit
aa2cb33
·
1 Parent(s): 738b6fb
Files changed (1) hide show
  1. backend/app.py +15 -0
backend/app.py CHANGED
@@ -488,12 +488,27 @@ async def predict(model_name: str = Form(...), file: UploadFile = File(...)):
488
  # Generate a brief AI interpretation using the Mistral client (if available)
489
  ai_interp = generate_mwt_summary(predicted_label, confidences, avg_confidence)
490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  return {
492
  "model_used": "MWT Classifier",
493
  "prediction": predicted_label,
494
  "confidence": confidences,
495
  "summary": {
496
  "ai_interpretation": ai_interp,
 
497
  },
498
  }
499
 
 
488
  # Generate a brief AI interpretation using the Mistral client (if available)
489
  ai_interp = generate_mwt_summary(predicted_label, confidences, avg_confidence)
490
 
491
+ # Save the input image to outputs/images so reports can embed it when no
492
+ # annotated image is produced by the model (MWT is a classifier only).
493
+ try:
494
+ os.makedirs(IMAGES_DIR, exist_ok=True)
495
+ input_filename = f"input_{uuid.uuid4().hex[:8]}.jpg"
496
+ input_path = os.path.join(IMAGES_DIR, input_filename)
497
+ # 'contents' was read earlier from the uploaded file
498
+ with open(input_path, 'wb') as out_f:
499
+ out_f.write(contents)
500
+ input_image_url = f"/outputs/images/{input_filename}"
501
+ except Exception as e:
502
+ print(f"⚠️ Failed to save input image for MWT report embedding: {e}")
503
+ input_image_url = ""
504
+
505
  return {
506
  "model_used": "MWT Classifier",
507
  "prediction": predicted_label,
508
  "confidence": confidences,
509
  "summary": {
510
  "ai_interpretation": ai_interp,
511
+ "annotated_image_url": input_image_url,
512
  },
513
  }
514