update app.py
Browse files
app.py
CHANGED
@@ -342,7 +342,7 @@ def ecg_analysis():
|
|
342 |
|
343 |
# Customize the plot layout
|
344 |
fig.update_layout(
|
345 |
-
title='Latent space 2D (PCA reduction)',
|
346 |
xaxis_title='component 1',
|
347 |
yaxis_title='component 2'
|
348 |
)
|
@@ -372,13 +372,38 @@ def ecg_analysis():
|
|
372 |
|
373 |
# DECODER RECONSTRUCTION PLOT
|
374 |
|
375 |
-
fig_reconstruction = plt.figure(figsize=(10,8))
|
376 |
-
sns.set(font_scale = 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
sns.set_style("white")
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
|
383 |
#classification probability
|
384 |
|
@@ -482,29 +507,61 @@ def ecg_analysis():
|
|
482 |
|
483 |
#clusters
|
484 |
|
485 |
-
fig_llm_cluster = plt.figure()
|
486 |
-
x = df_pca_llm['comp1']
|
487 |
-
y = df_pca_llm['comp2']
|
488 |
|
489 |
-
labels = ['Cluster 0', 'Cluster 1', 'Cluster 2', 'Cluster 3']
|
490 |
|
491 |
-
# Create a dictionary to map 'RestingECG' values to colors
|
492 |
-
color_mapping = {0: 'r', 1: 'b', 2: 'g', 3: 'y'}
|
493 |
|
494 |
-
for i in df_pca_llm['cluster'].unique():
|
495 |
-
|
496 |
-
|
497 |
|
498 |
-
plt.scatter(pca_llm_point['comp1'], pca_llm_point['comp1'], c='k', marker='D')
|
499 |
|
500 |
-
# Remove the numerical labels from the x and y axes
|
501 |
-
plt.xticks([])
|
502 |
-
plt.yticks([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
503 |
|
504 |
-
plt.xlabel('Principal Component 1')
|
505 |
-
plt.ylabel('Principal Component 2')
|
506 |
-
plt.legend()
|
507 |
-
plt.grid(False)
|
508 |
|
509 |
|
510 |
|
@@ -524,9 +581,11 @@ def ecg_analysis():
|
|
524 |
|
525 |
#demo app
|
526 |
|
527 |
-
|
|
|
|
|
528 |
|
529 |
-
with demo:
|
530 |
|
531 |
gr.Markdown("<h1><center>TIQUE: AI DEMO CAPABILITIES<center><h1>")
|
532 |
|
@@ -543,23 +602,23 @@ with demo:
|
|
543 |
|
544 |
with gr.Row():
|
545 |
|
546 |
-
input_file = gr.UploadButton("
|
547 |
text_upload_results = gr.Textbox()
|
548 |
|
549 |
input_file.upload(upload_ecg,inputs=[input_file],outputs=text_upload_results)
|
550 |
|
551 |
with gr.Row():
|
552 |
-
ecg_start_analysis_button = gr.Button(value="Start
|
553 |
|
554 |
|
555 |
-
gr.Markdown("##
|
556 |
|
557 |
with gr.Row():
|
558 |
|
559 |
llm_cluster = gr.Plot()
|
560 |
|
561 |
|
562 |
-
gr.Markdown("##
|
563 |
|
564 |
with gr.Row():
|
565 |
|
@@ -573,7 +632,7 @@ with demo:
|
|
573 |
|
574 |
classifier_nn_prediction = gr.Textbox()
|
575 |
|
576 |
-
gr.Markdown("##
|
577 |
|
578 |
with gr.Row():
|
579 |
|
|
|
342 |
|
343 |
# Customize the plot layout
|
344 |
fig.update_layout(
|
345 |
+
#title='Latent space 2D (PCA reduction)',
|
346 |
xaxis_title='component 1',
|
347 |
yaxis_title='component 2'
|
348 |
)
|
|
|
372 |
|
373 |
# DECODER RECONSTRUCTION PLOT
|
374 |
|
375 |
+
# fig_reconstruction = plt.figure(figsize=(10,8))
|
376 |
+
# sns.set(font_scale = 2)
|
377 |
+
# sns.set_style("white")
|
378 |
+
# plt.plot(df_data[0], 'black',linewidth=2)
|
379 |
+
# plt.plot(heartbeat_decoder_preds[0], 'red',linewidth=2)
|
380 |
+
# plt.fill_between(np.arange(140), heartbeat_decoder_preds[0], df_data[0], color='lightcoral')
|
381 |
+
# plt.legend(labels=["Input", "Reconstruction", "Error"])
|
382 |
+
|
383 |
+
fig_reconstruction = go.Figure()
|
384 |
+
|
385 |
+
sns.set(font_scale=2)
|
386 |
sns.set_style("white")
|
387 |
+
|
388 |
+
# Plot 'Input' and 'Reconstruction' lines
|
389 |
+
fig_reconstruction.add_trace(
|
390 |
+
go.Scatter(x=np.arange(140), y=df_data[0], fill=None, mode='lines', name='Input', line=dict(color='black', width=3)))
|
391 |
+
fig_reconstruction.add_trace(
|
392 |
+
go.Scatter(x=np.arange(140), y=heartbeat_decoder_preds[0], fill=None, mode='lines', name='Reconstruction',
|
393 |
+
line=dict(color='red', width=3)))
|
394 |
+
|
395 |
+
# Create a custom fill area
|
396 |
+
fill_x = list(np.arange(140)) + list(reversed(np.arange(140)))
|
397 |
+
fill_y = list(heartbeat_decoder_preds[0]) + list(reversed(df_data[0]))
|
398 |
+
fig_reconstruction.add_trace(go.Scatter(x=fill_x, y=fill_y, fill='tozeroy', fillcolor='rgba(255, 182, 193, 10.0)', mode='lines', line=dict(color='rgba(255, 182, 193, 0.5)', width=0), name='Error'))
|
399 |
+
|
400 |
+
# Customize the legend's position (outside the graph)
|
401 |
+
fig_reconstruction.update_layout(
|
402 |
+
legend=dict(
|
403 |
+
x=1.1, # Adjust the x-coordinate to position the legend outside
|
404 |
+
y=1.05, # Adjust the y-coordinate to position the legend
|
405 |
+
)
|
406 |
+
)
|
407 |
|
408 |
#classification probability
|
409 |
|
|
|
507 |
|
508 |
#clusters
|
509 |
|
510 |
+
# fig_llm_cluster = plt.figure()
|
511 |
+
# x = df_pca_llm['comp1']
|
512 |
+
# y = df_pca_llm['comp2']
|
513 |
|
514 |
+
# labels = ['Cluster 0', 'Cluster 1', 'Cluster 2', 'Cluster 3']
|
515 |
|
516 |
+
# # Create a dictionary to map 'RestingECG' values to colors
|
517 |
+
# color_mapping = {0: 'r', 1: 'b', 2: 'g', 3: 'y'}
|
518 |
|
519 |
+
# for i in df_pca_llm['cluster'].unique():
|
520 |
+
# color = color_mapping.get(i, 'k') # Use 'k' (black) for undefined values
|
521 |
+
# plt.scatter(x[df_pca_llm['cluster'] == i], y[df_pca_llm['cluster'] == i], c=color, label=labels[i])
|
522 |
|
523 |
+
# plt.scatter(pca_llm_point['comp1'], pca_llm_point['comp1'], c='k', marker='D')
|
524 |
|
525 |
+
# # Remove the numerical labels from the x and y axes
|
526 |
+
# plt.xticks([])
|
527 |
+
# plt.yticks([])
|
528 |
+
|
529 |
+
# plt.xlabel('Principal Component 1')
|
530 |
+
# plt.ylabel('Principal Component 2')
|
531 |
+
# plt.legend()
|
532 |
+
# plt.grid(False)
|
533 |
+
|
534 |
+
fig_llm_cluster = go.Figure() #use plotly for this, otherwise with matplotlib the legend will be ouside of the image when we use gradio
|
535 |
+
|
536 |
+
for cluster in df_pca_llm['cluster'].unique():
|
537 |
+
cluster_data = df_pca_llm[df_pca_llm['cluster'] == cluster]
|
538 |
+
fig_llm_cluster.add_trace(
|
539 |
+
go.Scatter(x=cluster_data['comp1'], y=cluster_data['comp2'], mode='markers', name=f'Cluster {cluster}'))
|
540 |
+
|
541 |
+
# Customize the marker size
|
542 |
+
fig_llm_cluster.update_traces(marker=dict(size=12))
|
543 |
+
|
544 |
+
# Set axis labels
|
545 |
+
fig_llm_cluster.update_xaxes(title_text="Principal Component 1")
|
546 |
+
fig_llm_cluster.update_yaxes(title_text="Principal Component 2")
|
547 |
+
|
548 |
+
# Add the additional point
|
549 |
+
fig_llm_cluster.add_trace(
|
550 |
+
go.Scatter(x=pca_llm_point['comp1'], y=pca_llm_point['comp2'], mode='markers', name='Patient',
|
551 |
+
marker=dict(size=12, symbol='diamond', line=dict(width=2, color='Black'))))
|
552 |
+
|
553 |
+
# Customize the legend's position (outside the graph)
|
554 |
+
fig_llm_cluster.update_layout(
|
555 |
+
legend=dict(
|
556 |
+
x=1.05, # Adjust the x-coordinate to position the legend outside
|
557 |
+
y=1 # Adjust the y-coordinate to position the legend
|
558 |
+
)
|
559 |
+
)
|
560 |
+
|
561 |
+
# Deactivate the grid
|
562 |
+
fig_llm_cluster.update_xaxes(showgrid=False)
|
563 |
+
fig_llm_cluster.update_yaxes(showgrid=False)
|
564 |
|
|
|
|
|
|
|
|
|
565 |
|
566 |
|
567 |
|
|
|
581 |
|
582 |
#demo app
|
583 |
|
584 |
+
with gr.Blocks(title="TIQUE - AI DEMO CAPABILITIES") as demo:
|
585 |
+
|
586 |
+
# demo = gr.Blocks()
|
587 |
|
588 |
+
# with demo:
|
589 |
|
590 |
gr.Markdown("<h1><center>TIQUE: AI DEMO CAPABILITIES<center><h1>")
|
591 |
|
|
|
602 |
|
603 |
with gr.Row():
|
604 |
|
605 |
+
input_file = gr.UploadButton("Upload patient's data and latest ECG π")
|
606 |
text_upload_results = gr.Textbox()
|
607 |
|
608 |
input_file.upload(upload_ecg,inputs=[input_file],outputs=text_upload_results)
|
609 |
|
610 |
with gr.Row():
|
611 |
+
ecg_start_analysis_button = gr.Button(value="Start data analysis",scale=1)
|
612 |
|
613 |
|
614 |
+
gr.Markdown("## Patient positioning on clusters")
|
615 |
|
616 |
with gr.Row():
|
617 |
|
618 |
llm_cluster = gr.Plot()
|
619 |
|
620 |
|
621 |
+
gr.Markdown("## ECG analysis:")
|
622 |
|
623 |
with gr.Row():
|
624 |
|
|
|
632 |
|
633 |
classifier_nn_prediction = gr.Textbox()
|
634 |
|
635 |
+
gr.Markdown("## Patient's classification based on Chest Pain Type and ST Slope:")
|
636 |
|
637 |
with gr.Row():
|
638 |
|