malavikapradeep2001 commited on
Commit
8b3e779
·
1 Parent(s): 8bf4cb9
Files changed (1) hide show
  1. backend/app.py +21 -1
backend/app.py CHANGED
@@ -971,6 +971,26 @@ async def generate_report(
971
  annotated_img_full = ''
972
  annotated_img = annotated_img_full
973
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
974
  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 ''
975
 
976
  # Format generated time
@@ -1068,7 +1088,7 @@ async def generate_report(
1068
  </div>
1069
  </div>
1070
 
1071
- {'<div class="full"><div class="section-title">Annotated Analysis Image</div><img src="' + annotated_img_full + '" class="annotated-image" alt="Annotated Analysis Result" /></div>' if annotated_img else ''}
1072
 
1073
  <div class="full">
1074
  <div class="section-title">Doctor\'s Notes</div>
 
971
  annotated_img_full = ''
972
  annotated_img = annotated_img_full
973
 
974
+ # Compute a display path for the HTML. Prefer a relative filename when the
975
+ # annotated image is copied into the same report folder. This makes the
976
+ # HTML work when opened directly from disk (or via HF file viewer).
977
+ annotated_img_display = annotated_img_full
978
+ try:
979
+ if annotated_img_local:
980
+ annotated_img_local_abs = os.path.abspath(annotated_img_local)
981
+ report_dir_abs = os.path.abspath(report_dir)
982
+ # If the annotated image resides in the report folder, reference by basename
983
+ if os.path.commonpath([annotated_img_local_abs, report_dir_abs]) == report_dir_abs:
984
+ annotated_img_display = os.path.basename(annotated_img_local_abs)
985
+ else:
986
+ # If annotated image is inside the outputs/reports/<report_id>/ path but not same
987
+ # absolute path (edge cases), make it relative to the report dir
988
+ prefix = f"/outputs/reports/{report_id}/"
989
+ if isinstance(annotated_img_full, str) and annotated_img_full.startswith(prefix):
990
+ annotated_img_display = annotated_img_full[len(prefix):]
991
+ except Exception:
992
+ annotated_img_display = annotated_img_full
993
+
994
  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 ''
995
 
996
  # Format generated time
 
1088
  </div>
1089
  </div>
1090
 
1091
+ {'<div class="full"><div class="section-title">Annotated Analysis Image</div><img src="' + annotated_img_display + '" class="annotated-image" alt="Annotated Analysis Result" /></div>' if annotated_img else ''}
1092
 
1093
  <div class="full">
1094
  <div class="section-title">Doctor\'s Notes</div>