Analysis selection improvements.
Browse files- app.py +43 -40
- version.py +2 -2
app.py
CHANGED
|
@@ -39,6 +39,8 @@ import ecg_plot
|
|
| 39 |
import getopt
|
| 40 |
import gradio
|
| 41 |
import io
|
|
|
|
|
|
|
| 42 |
import matplotlib.pyplot as plt
|
| 43 |
import matplotlib.ticker
|
| 44 |
import neurokit2
|
|
@@ -196,16 +198,6 @@ def predict(numberOfECGs: int = 1,
|
|
| 196 |
return plotList
|
| 197 |
|
| 198 |
|
| 199 |
-
# ###### Select ECG in the gallery ##########################################
|
| 200 |
-
def select(event: gradio.SelectData,
|
| 201 |
-
request: gradio.Request):
|
| 202 |
-
# Get selection index from Gallery select() event:
|
| 203 |
-
# https://github.com/gradio-app/gradio/issues/1976#issuecomment-1726018500
|
| 204 |
-
|
| 205 |
-
Sessions[request.session_hash].Selected = event.index
|
| 206 |
-
log(f'Session "{request.session_hash}": Selected ECG #{Sessions[request.session_hash].Selected + 1}')
|
| 207 |
-
|
| 208 |
-
|
| 209 |
# ###### Download CSV #######################################################
|
| 210 |
def downloadCSV(request: gradio.Request) -> pathlib.Path:
|
| 211 |
|
|
@@ -239,9 +231,21 @@ def downloadPDF(request: gradio.Request) -> pathlib.Path:
|
|
| 239 |
return fileName
|
| 240 |
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
# ###### Analyze the selected ECG ###########################################
|
| 243 |
-
def analyze(
|
|
|
|
| 244 |
|
|
|
|
| 245 |
log(f'Session "{request.session_hash}": Analyze ECG #{Sessions[request.session_hash].Selected + 1}!')
|
| 246 |
|
| 247 |
data = Sessions[request.session_hash].Results[Sessions[request.session_hash].Selected]
|
|
@@ -285,9 +289,9 @@ div {
|
|
| 285 |
|
| 286 |
/* ###### General Settings ############################################## */
|
| 287 |
html, body {
|
| 288 |
-
|
| 289 |
-
padding: 0;
|
| 290 |
margin: 0;
|
|
|
|
| 291 |
font-family: sans-serif;
|
| 292 |
font-size: small;
|
| 293 |
background-color: #E3E3E3; /* Simula background colour: #E3E3E3 */
|
|
@@ -373,7 +377,7 @@ if len(args) > 0:
|
|
| 373 |
|
| 374 |
# ====== Create GUI =========================================================
|
| 375 |
with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.themes.colors.blue),
|
| 376 |
-
fill_height =
|
| 377 |
|
| 378 |
# ====== Session handling ================================================
|
| 379 |
# Session initialization, to be called when page is loaded
|
|
@@ -395,43 +399,38 @@ with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.t
|
|
| 395 |
</div>
|
| 396 |
""")
|
| 397 |
|
| 398 |
-
gradio.Markdown('## Settings')
|
| 399 |
-
|
|
|
|
| 400 |
sliderNumberOfECGs = gradio.Slider(1, 100, label="Number of ECGs", step = 1, value = 4, interactive = True)
|
| 401 |
# sliderLengthInSeconds = gradio.Slider(5, 60, label="Length (s)", step = 5, value = 10, interactive = True)
|
| 402 |
dropdownType = gradio.Dropdown( [ 'ECG-12', 'ECG-8' ], label = 'ECG Type', interactive = True)
|
| 403 |
dropdownGeneratorModel = gradio.Dropdown( [ 'Default' ], label = 'Generator Model', interactive = True)
|
| 404 |
with gradio.Column():
|
| 405 |
buttonGenerate = gradio.Button("Generate ECGs!")
|
| 406 |
-
buttonAnalyze = gradio.Button("Analyze this ECG!")
|
| 407 |
with gradio.Row():
|
| 408 |
buttonCSV = gradio.DownloadButton("Download CSV")
|
| 409 |
buttonCSV_hidden = gradio.DownloadButton(visible=False, elem_id="download_csv_hidden")
|
| 410 |
buttonPDF = gradio.DownloadButton("Download PDF")
|
| 411 |
buttonPDF_hidden = gradio.DownloadButton(visible=False, elem_id="download_pdf_hidden")
|
| 412 |
|
| 413 |
-
gradio.Markdown('## Output')
|
| 414 |
|
| 415 |
-
|
|
|
|
| 416 |
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
height = 'auto',
|
| 427 |
-
object_fit = 'contain',
|
| 428 |
-
show_label = True,
|
| 429 |
-
allow_preview = True,
|
| 430 |
-
preview = False
|
| 431 |
)
|
| 432 |
-
outputGallery.select(select)
|
| 433 |
-
|
| 434 |
-
|
| 435 |
|
| 436 |
# ====== Add click event handling for "Generate" button ==================
|
| 437 |
buttonGenerate.click(predict,
|
|
@@ -443,10 +442,14 @@ with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.t
|
|
| 443 |
)
|
| 444 |
|
| 445 |
# ====== Add click event handling for "Analyze" button ===================
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
# ====== Add click event handling for download buttons ===================
|
| 452 |
# Using hidden button and JavaScript, to generate download file on-the-fly:
|
|
|
|
| 39 |
import getopt
|
| 40 |
import gradio
|
| 41 |
import io
|
| 42 |
+
import matplotlib
|
| 43 |
+
matplotlib.use('Agg')
|
| 44 |
import matplotlib.pyplot as plt
|
| 45 |
import matplotlib.ticker
|
| 46 |
import neurokit2
|
|
|
|
| 198 |
return plotList
|
| 199 |
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
# ###### Download CSV #######################################################
|
| 202 |
def downloadCSV(request: gradio.Request) -> pathlib.Path:
|
| 203 |
|
|
|
|
| 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 ###########################################
|
| 245 |
+
def analyze(event: gradio.SelectData,
|
| 246 |
+
request: gradio.Request) -> matplotlib.figure.Figure:
|
| 247 |
|
| 248 |
+
Sessions[request.session_hash].Selected = event.index
|
| 249 |
log(f'Session "{request.session_hash}": Analyze ECG #{Sessions[request.session_hash].Selected + 1}!')
|
| 250 |
|
| 251 |
data = Sessions[request.session_hash].Results[Sessions[request.session_hash].Selected]
|
|
|
|
| 289 |
|
| 290 |
/* ###### General Settings ############################################## */
|
| 291 |
html, body {
|
| 292 |
+
height: 100%;
|
|
|
|
| 293 |
margin: 0;
|
| 294 |
+
padding: 0;
|
| 295 |
font-family: sans-serif;
|
| 296 |
font-size: small;
|
| 297 |
background-color: #E3E3E3; /* Simula background colour: #E3E3E3 */
|
|
|
|
| 377 |
|
| 378 |
# ====== Create GUI =========================================================
|
| 379 |
with gradio.Blocks(css = css, theme = gradio.themes.Glass(secondary_hue=gradio.themes.colors.blue),
|
| 380 |
+
fill_height = True, fill_width = True) as gui:
|
| 381 |
|
| 382 |
# ====== Session handling ================================================
|
| 383 |
# Session initialization, to be called when page is loaded
|
|
|
|
| 399 |
</div>
|
| 400 |
""")
|
| 401 |
|
| 402 |
+
# gradio.Markdown('## Settings')
|
| 403 |
+
|
| 404 |
+
with gradio.Row(height = '12vh', min_height = '12vh', max_height = '12vh'):
|
| 405 |
sliderNumberOfECGs = gradio.Slider(1, 100, label="Number of ECGs", step = 1, value = 4, interactive = True)
|
| 406 |
# sliderLengthInSeconds = gradio.Slider(5, 60, label="Length (s)", step = 5, value = 10, interactive = True)
|
| 407 |
dropdownType = gradio.Dropdown( [ 'ECG-12', 'ECG-8' ], label = 'ECG Type', interactive = True)
|
| 408 |
dropdownGeneratorModel = gradio.Dropdown( [ 'Default' ], label = 'Generator Model', interactive = True)
|
| 409 |
with gradio.Column():
|
| 410 |
buttonGenerate = gradio.Button("Generate ECGs!")
|
| 411 |
+
# buttonAnalyze = gradio.Button("Analyze this ECG!")
|
| 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 |
|
| 420 |
+
with gradio.Row(): # height = '24vh', min_height = '24vh', max_height = '24vh'):
|
| 421 |
+
analysisOutput = gradio.Plot(label = 'Analysis')
|
| 422 |
|
| 423 |
+
with gradio.Row(): # height = '24vh', min_height = '24vh', max_height = '24vh'):
|
| 424 |
+
outputGallery = gradio.Gallery(label = 'ECG',
|
| 425 |
+
columns = 8,
|
| 426 |
+
rows = 1,
|
| 427 |
+
height = 'auto',
|
| 428 |
+
object_fit = 'contain',
|
| 429 |
+
show_label = True,
|
| 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 |
)
|
| 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 ]
|
| 452 |
+
)
|
| 453 |
|
| 454 |
# ====== Add click event handling for download buttons ===================
|
| 455 |
# Using hidden button and JavaScript, to generate download file on-the-fly:
|
version.py
CHANGED
|
@@ -33,8 +33,8 @@
|
|
| 33 |
# * Thomas Dreibholz <[email protected]>
|
| 34 |
|
| 35 |
DEEPFAKEECGGENPLUS_VERSION_MAJOR = 0
|
| 36 |
-
DEEPFAKEECGGENPLUS_VERSION_MINOR =
|
| 37 |
-
DEEPFAKEECGGENPLUS_VERSION_PATCH = "0~
|
| 38 |
DEEPFAKEECGGENPLUS_VERSION = str(DEEPFAKEECGGENPLUS_VERSION_MAJOR) + '.' + \
|
| 39 |
str(DEEPFAKEECGGENPLUS_VERSION_MINOR) + '.' + \
|
| 40 |
str(DEEPFAKEECGGENPLUS_VERSION_PATCH)
|
|
|
|
| 33 |
# * Thomas Dreibholz <[email protected]>
|
| 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)
|