malavikapradeep2001 commited on
Commit
b56d2fb
·
1 Parent(s): e75450b
Files changed (1) hide show
  1. backend/app.py +13 -10
backend/app.py CHANGED
@@ -808,16 +808,19 @@ async def generate_report(
808
  report_html = os.path.join(report_dir, "report.html")
809
  json_url = f"/outputs/reports/{report_id}/report.json"
810
  html_url = f"/outputs/reports/{report_id}/report.html"
811
- annotated_img = report_data.get("analysis", {}).get("annotated_image_url") or ""
812
-
813
- # Use relative path (same origin) for annotated image so the report works both
814
- # locally and when deployed (avoid hardcoding localhost or a specific port).
815
- # If `annotated_img` is an absolute URL (starts with http), leave it unchanged.
816
- if annotated_img and annotated_img.startswith('http'):
817
- annotated_img_full = annotated_img
818
- else:
819
- # Keep relative path like "/outputs/images/.." so browser requests same host
820
- annotated_img_full = annotated_img or ""
 
 
 
821
 
822
  download_pdf_btn = f'<a href="{pdf_url}" download style="text-decoration:none"><button class="btn-secondary">Download PDF</button></a>' if pdf_url else ''
823
 
 
808
  report_html = os.path.join(report_dir, "report.html")
809
  json_url = f"/outputs/reports/{report_id}/report.json"
810
  html_url = f"/outputs/reports/{report_id}/report.html"
811
+
812
+ # Prefer annotated image URL from the analysis summary (ai_summary) if present,
813
+ # otherwise fall back to the analysis annotated_image_url (which may be the analysis_id).
814
+ annotated_img = ai_summary.get('annotated_image_url') or report_data.get("analysis", {}).get("annotated_image_url") or ""
815
+
816
+ # Normalize annotated image path: allow absolute http(s) URLs or ensure relative paths start with '/'.
817
+ annotated_img_full = ""
818
+ if annotated_img:
819
+ if isinstance(annotated_img, str) and annotated_img.startswith(('http://', 'https://')):
820
+ annotated_img_full = annotated_img
821
+ else:
822
+ # ensure leading slash for relative paths so StaticFiles routing works
823
+ annotated_img_full = annotated_img if str(annotated_img).startswith('/') else '/' + str(annotated_img)
824
 
825
  download_pdf_btn = f'<a href="{pdf_url}" download style="text-decoration:none"><button class="btn-secondary">Download PDF</button></a>' if pdf_url else ''
826