Nj-1111 commited on
Commit
686b162
Β·
verified Β·
1 Parent(s): de441de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -72
app.py CHANGED
@@ -28,7 +28,7 @@ print(f"Loading model repo={REPO_ID} epoch={'latest' if EPOCH is None else EPOCH
28
  pipeline = Phase3Pipeline(
29
  repo_id=REPO_ID,
30
  epoch=EPOCH,
31
- mc_passes=1,
32
  uncertainty_threshold=0.05,
33
  token=TOKEN,
34
  )
@@ -96,70 +96,6 @@ def _build_text(r: dict, mc_passes: int) -> str:
96
  return "\n".join(lines)
97
 
98
 
99
- def _rejection_text(confidence: float, reason: str) -> str:
100
- lines = [
101
- "=" * 52,
102
- " GLAUCOMA CDSS β€” INPUT REJECTED",
103
- "=" * 52,
104
- "",
105
- " This image does not appear to be a retinal",
106
- " fundus photograph.",
107
- "",
108
- f" Validator confidence : {confidence:.4f}",
109
- f" Validator detail : {reason}",
110
- "",
111
- " Please upload a proper retinal fundus image.",
112
- " Accepted sources:",
113
- " - Fundus camera photograph",
114
- " - JPEG or PNG format",
115
- " - Clear view of the optic disc",
116
- "",
117
- "=" * 52,
118
- ]
119
- return "\n".join(lines)
120
-
121
-
122
-
123
- # ── PDF BUILDER ───────────────────────────────────────────────────────────
124
- def _build_pdf(text: str):
125
-
126
- try:
127
- from fpdf import FPDF
128
-
129
- # Remove unsupported unicode characters
130
- safe_text = (
131
- text.replace("β€”", "-")
132
- .replace("β€’", "-")
133
- .replace("β†’", "->")
134
- )
135
-
136
- pdf = FPDF()
137
-
138
- pdf.add_page()
139
-
140
- pdf.set_auto_page_break(auto=True, margin=15)
141
-
142
- pdf.set_font("Courier", size=10)
143
-
144
- for line in safe_text.splitlines():
145
- pdf.multi_cell(0, 6, txt=line)
146
-
147
- out = tempfile.NamedTemporaryFile(
148
- delete=False,
149
- suffix=".pdf"
150
- )
151
-
152
- pdf.output(out.name)
153
-
154
- return out.name
155
-
156
- except Exception as e:
157
-
158
- print("PDF generation failed:", repr(e))
159
-
160
- return None
161
-
162
-
163
  # ── INFERENCE ─────────────────────────────────────────────────────────────
164
  def analyse(file_path):
165
  if file_path is None:
@@ -175,13 +111,10 @@ def analyse(file_path):
175
  print("Pipeline inference completed.")
176
 
177
  text = _build_text(result["report"], pipeline.mc_passes)
178
- pdf = _build_pdf(text)
179
-
180
  status = "Analysis completed successfully."
181
- if pdf is None:
182
- status = "Analysis completed, but PDF generation failed."
183
 
184
- return text, pdf, status
185
 
186
  except Exception as e:
187
  print(f"Analysis error: {e}")
@@ -224,7 +157,6 @@ with gr.Blocks(title="Glaucoma CDSS") as demo:
224
  interactive=False,
225
  )
226
 
227
- pdf_out = gr.File(label="Download PDF Report")
228
 
229
  gr.Markdown(
230
  "_Research prototype β€” NOT a medical device. "
@@ -327,7 +259,7 @@ All clinical decisions must be made by a qualified ophthalmologist.
327
  ).then(
328
  fn=analyse,
329
  inputs=[file_in],
330
- outputs=[report_box, pdf_out, status_box],
331
  ).then(
332
  fn=set_ready,
333
  inputs=None,
 
28
  pipeline = Phase3Pipeline(
29
  repo_id=REPO_ID,
30
  epoch=EPOCH,
31
+ mc_passes=2,
32
  uncertainty_threshold=0.05,
33
  token=TOKEN,
34
  )
 
96
  return "\n".join(lines)
97
 
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  # ── INFERENCE ─────────────────────────────────────────────────────────────
100
  def analyse(file_path):
101
  if file_path is None:
 
111
  print("Pipeline inference completed.")
112
 
113
  text = _build_text(result["report"], pipeline.mc_passes)
 
 
114
  status = "Analysis completed successfully."
115
+
 
116
 
117
+ return text, status
118
 
119
  except Exception as e:
120
  print(f"Analysis error: {e}")
 
157
  interactive=False,
158
  )
159
 
 
160
 
161
  gr.Markdown(
162
  "_Research prototype β€” NOT a medical device. "
 
259
  ).then(
260
  fn=analyse,
261
  inputs=[file_in],
262
+ outputs=[report_box, status_box],
263
  ).then(
264
  fn=set_ready,
265
  inputs=None,