dreibh commited on
Commit
5e932f3
·
verified ·
1 Parent(s): 6a855de

GUI improvements.

Browse files
Files changed (2) hide show
  1. app.py +57 -44
  2. version.py +1 -1
app.py CHANGED
@@ -198,47 +198,53 @@ def predict(numberOfECGs: int = 1,
198
  return plotList
199
 
200
 
201
- # ###### Download CSV #######################################################
202
- def downloadCSV(request: gradio.Request) -> pathlib.Path:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
- ecgResult = Sessions[request.session_hash].Results[Sessions[request.session_hash].Selected]
205
- ecgType = Sessions[request.session_hash].Type
206
- fileName = pathlib.Path(Sessions[request.session_hash].TempDirectory.name) / \
207
- ('ECG-' + str(Sessions[request.session_hash].Selected + 1) + '.csv')
208
- deepfakeecg.dataToCSV(ecgResult, ecgType, fileName)
209
 
210
- log(f'Session "{request.session_hash}": Download CSV file {fileName}')
211
- return fileName
212
 
213
 
 
 
 
 
214
 
215
  # ###### Download PDF #######################################################
216
  def downloadPDF(request: gradio.Request) -> pathlib.Path:
 
217
 
218
- ecgResult = Sessions[request.session_hash].Results[Sessions[request.session_hash].Selected]
219
- ecgType = Sessions[request.session_hash].Type
220
- fileName = pathlib.Path(Sessions[request.session_hash].TempDirectory.name) / \
221
- ('ECG-' + str(Sessions[request.session_hash].Selected + 1) + '.pdf')
222
- if ecgType == deepfakeecg.DATA_ECG12:
223
- outputLeads = [ 'I', 'II', 'III', 'aVL', 'aVR', 'aVF', 'V1', 'V2', 'V3', 'V4' , 'V5' , 'V6' ]
224
- else:
225
- outputLeads = [ 'I', 'II', 'V1', 'V2', 'V3', 'V4' , 'V5' , 'V6' ]
226
-
227
- deepfakeecg.dataToPDF(ecgResult, ecgType, outputLeads, fileName,
228
- Sessions[request.session_hash].Selected + 1)
229
-
230
- log(f'Session "{request.session_hash}": Download PDF file {fileName}')
231
- return fileName
232
 
233
-
234
- # # ###### Select ECG in the gallery ##########################################
235
- # def select(event: gradio.SelectData,
236
- # request: gradio.Request):
237
- # # Get selection index from Gallery select() event:
238
- # # https://github.com/gradio-app/gradio/issues/1976#issuecomment-1726018500
239
- #
240
- # Sessions[request.session_hash].Selected = event.index
241
- # log(f'Session "{request.session_hash}": Selected ECG #{Sessions[request.session_hash].Selected + 1}')
242
 
243
 
244
  # ###### Analyze the selected ECG ###########################################
@@ -412,8 +418,10 @@ with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.t
412
  with gradio.Row():
413
  buttonCSV = gradio.DownloadButton("Download CSV")
414
  buttonCSV_hidden = gradio.DownloadButton(visible=False, elem_id="download_csv_hidden")
415
- buttonPDF = gradio.DownloadButton("Download PDF")
416
  buttonPDF_hidden = gradio.DownloadButton(visible=False, elem_id="download_pdf_hidden")
 
 
417
 
418
  # gradio.Markdown('## Output')
419
 
@@ -430,7 +438,6 @@ with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.t
430
  allow_preview = True,
431
  preview = False
432
  )
433
- # outputGallery.select(select)
434
 
435
  # ====== Add click event handling for "Generate" button ==================
436
  buttonGenerate.click(predict,
@@ -442,10 +449,6 @@ with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.t
442
  )
443
 
444
  # ====== Add click event handling for "Analyze" button ===================
445
- # outputGallery.click(analyze,
446
- # inputs = [ ],
447
- # outputs = [ analysisOutput ]
448
- # )
449
  outputGallery.select(analyze,
450
  inputs = [ ],
451
  outputs = [ analysisOutput ]
@@ -455,13 +458,23 @@ with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.t
455
  # Using hidden button and JavaScript, to generate download file on-the-fly:
456
  # https://github.com/gradio-app/gradio/issues/9230#issuecomment-2323771634
457
  buttonCSV.click(downloadCSV)
458
- buttonCSV.click(fn = downloadCSV, inputs = None, outputs = [ buttonCSV_hidden ]).then(
459
- fn = None, inputs = None, outputs = None,
460
- js = "() => document.querySelector('#download_csv_hidden').click()")
 
 
461
  buttonPDF.click(downloadPDF)
462
- buttonPDF.click(fn = downloadPDF, inputs = None, outputs = [ buttonPDF_hidden ]).then(
463
- fn = None, inputs = None, outputs = None,
464
- js = "() => document.querySelector('#download_pdf_hidden').click()")
 
 
 
 
 
 
 
 
465
 
466
  # ====== Run on startup ==================================================
467
  gui.load(predict,
 
198
  return plotList
199
 
200
 
201
+ # ###### Generic download ###################################################
202
+ def download(request: gradio.Request,
203
+ outputFormat: int) -> pathlib.Path:
204
+
205
+ if outputFormat == deepfakeecg.OUTPUT_CSV:
206
+ ecgResult = Sessions[request.session_hash].Results[Sessions[request.session_hash].Selected]
207
+ ecgType = Sessions[request.session_hash].Type
208
+ fileName = pathlib.Path(Sessions[request.session_hash].TempDirectory.name) / \
209
+ ('ECG-' + str(Sessions[request.session_hash].Selected + 1) + '.csv')
210
+ deepfakeecg.dataToCSV(ecgResult, ecgType, fileName)
211
+
212
+ log(f'Session "{request.session_hash}": Download CSV file {fileName}')
213
+ return fileName
214
+
215
+ elif ( (outputFormat == deepfakeecg.OUTPUT_PDF) or
216
+ (outputFormat == deepfakeecg.OUTPUT_PDF_ANALYSIS) ):
217
+
218
+ ecgResult = Sessions[request.session_hash].Results[Sessions[request.session_hash].Selected]
219
+ ecgType = Sessions[request.session_hash].Type
220
+ fileName = pathlib.Path(Sessions[request.session_hash].TempDirectory.name) / \
221
+ ('ECG-' + str(Sessions[request.session_hash].Selected + 1) + '.pdf')
222
+ if ecgType == deepfakeecg.DATA_ECG12:
223
+ outputLeads = [ 'I', 'II', 'III', 'aVL', 'aVR', 'aVF', 'V1', 'V2', 'V3', 'V4' , 'V5' , 'V6' ]
224
+ else:
225
+ outputLeads = [ 'I', 'II', 'V1', 'V2', 'V3', 'V4' , 'V5' , 'V6' ]
226
 
227
+ deepfakeecg.dataToPDF(ecgResult, ecgType, outputLeads, fileName,
228
+ Sessions[request.session_hash].Selected + 1,
229
+ outputFormat)
 
 
230
 
231
+ log(f'Session "{request.session_hash}": Download PDF file {fileName}')
232
+ return fileName
233
 
234
 
235
+ # ###### Download CSV #######################################################
236
+ def downloadCSV(request: gradio.Request) -> pathlib.Path:
237
+ return download(request, deepfakeecg.OUTPUT_CSV)
238
+
239
 
240
  # ###### Download PDF #######################################################
241
  def downloadPDF(request: gradio.Request) -> pathlib.Path:
242
+ return download(request, deepfakeecg.OUTPUT_PDF_ANALYSIS)
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
 
245
+ # ###### Download PDF #######################################################
246
+ def downloadPDFwithAnalysis(request: gradio.Request) -> pathlib.Path:
247
+ return download(request, 'pdf-with-analysis')
 
 
 
 
 
 
248
 
249
 
250
  # ###### Analyze the selected ECG ###########################################
 
418
  with gradio.Row():
419
  buttonCSV = gradio.DownloadButton("Download CSV")
420
  buttonCSV_hidden = gradio.DownloadButton(visible=False, elem_id="download_csv_hidden")
421
+ buttonPDF = gradio.DownloadButton("Download ECG PDF")
422
  buttonPDF_hidden = gradio.DownloadButton(visible=False, elem_id="download_pdf_hidden")
423
+ buttonPDFwAnalysis = gradio.DownloadButton("Download ECG+Analysis PDF")
424
+ buttonPDFwAnalysis_hidden = gradio.DownloadButton(visible=False, elem_id="download_pdfwanalysis_hidden")
425
 
426
  # gradio.Markdown('## Output')
427
 
 
438
  allow_preview = True,
439
  preview = False
440
  )
 
441
 
442
  # ====== Add click event handling for "Generate" button ==================
443
  buttonGenerate.click(predict,
 
449
  )
450
 
451
  # ====== Add click event handling for "Analyze" button ===================
 
 
 
 
452
  outputGallery.select(analyze,
453
  inputs = [ ],
454
  outputs = [ analysisOutput ]
 
458
  # Using hidden button and JavaScript, to generate download file on-the-fly:
459
  # https://github.com/gradio-app/gradio/issues/9230#issuecomment-2323771634
460
  buttonCSV.click(downloadCSV)
461
+ buttonCSV.click(fn = downloadCSV,
462
+ inputs = None,
463
+ outputs = [ buttonCSV_hidden ]).then(
464
+ fn = None, inputs = None, outputs = None,
465
+ js = "() => document.querySelector('#download_csv_hidden').click()")
466
  buttonPDF.click(downloadPDF)
467
+ buttonPDF.click(fn = downloadPDF,
468
+ inputs = None,
469
+ outputs = [ buttonPDF_hidden ]).then(
470
+ fn = None, inputs = None, outputs = None,
471
+ js = "() => document.querySelector('#download_pdf_hidden').click()")
472
+ buttonPDFwAnalysis.click(downloadPDFwithAnalysis)
473
+ buttonPDFwAnalysis.click(fn = downloadPDFwithAnalysis,
474
+ inputs = None,
475
+ outputs = [ buttonPDFwAnalysis_hidden ]).then(
476
+ fn = None, inputs = None, outputs = None,
477
+ js = "() => document.querySelector('#download_pdfwanalysis_hidden').click()")
478
 
479
  # ====== Run on startup ==================================================
480
  gui.load(predict,
version.py CHANGED
@@ -34,7 +34,7 @@
34
 
35
  DEEPFAKEECGGENPLUS_VERSION_MAJOR = 0
36
  DEEPFAKEECGGENPLUS_VERSION_MINOR = 6
37
- DEEPFAKEECGGENPLUS_VERSION_PATCH = "0~beta1"
38
  DEEPFAKEECGGENPLUS_VERSION = str(DEEPFAKEECGGENPLUS_VERSION_MAJOR) + '.' + \
39
  str(DEEPFAKEECGGENPLUS_VERSION_MINOR) + '.' + \
40
  str(DEEPFAKEECGGENPLUS_VERSION_PATCH)
 
34
 
35
  DEEPFAKEECGGENPLUS_VERSION_MAJOR = 0
36
  DEEPFAKEECGGENPLUS_VERSION_MINOR = 6
37
+ DEEPFAKEECGGENPLUS_VERSION_PATCH = "0~beta2"
38
  DEEPFAKEECGGENPLUS_VERSION = str(DEEPFAKEECGGENPLUS_VERSION_MAJOR) + '.' + \
39
  str(DEEPFAKEECGGENPLUS_VERSION_MINOR) + '.' + \
40
  str(DEEPFAKEECGGENPLUS_VERSION_PATCH)