Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ def beam_prediction_task(data_percentage, task_complexity, theme):
|
|
| 26 |
raw_cm_path = os.path.join(raw_folder, "confusion_matrix_raw.png")
|
| 27 |
plot_confusion_matrix_beamPred(raw_cm,
|
| 28 |
classes=np.arange(raw_cm.shape[0]),
|
| 29 |
-
title=f"Raw Confusion Matrix\n
|
| 30 |
save_path=raw_cm_path,
|
| 31 |
theme=theme)
|
| 32 |
raw_img = Image.open(raw_cm_path)
|
|
@@ -39,7 +39,7 @@ def beam_prediction_task(data_percentage, task_complexity, theme):
|
|
| 39 |
embeddings_cm_path = os.path.join(embeddings_folder, "confusion_matrix_embeddings.png")
|
| 40 |
plot_confusion_matrix_beamPred(embeddings_cm,
|
| 41 |
classes=np.arange(embeddings_cm.shape[0]),
|
| 42 |
-
title=f"Embeddings Confusion Matrix\n
|
| 43 |
save_path=embeddings_cm_path,
|
| 44 |
theme=theme)
|
| 45 |
embeddings_img = Image.open(embeddings_cm_path)
|
|
@@ -76,7 +76,8 @@ def plot_confusion_matrix_beamPred(cm, classes, title, save_path, theme='Light')
|
|
| 76 |
plt.style.use('dark_background') # Use dark mode styling
|
| 77 |
#text_color = 'white'
|
| 78 |
text_color = 'gray'
|
| 79 |
-
cmap = 'cividis' # Dark-mode-friendly colormap
|
|
|
|
| 80 |
else:
|
| 81 |
plt.style.use('default') # Use default (light) mode styling
|
| 82 |
#text_color = 'black'
|
|
@@ -86,10 +87,10 @@ def plot_confusion_matrix_beamPred(cm, classes, title, save_path, theme='Light')
|
|
| 86 |
plt.figure(figsize=(10, 10))
|
| 87 |
|
| 88 |
# Plot the confusion matrix with a colormap compatible for the mode
|
| 89 |
-
sns.heatmap(cm, cmap=cmap, cbar=True, linecolor=text_color
|
| 90 |
|
| 91 |
# Add F1-score to the title
|
| 92 |
-
plt.title(f"{title}\
|
| 93 |
|
| 94 |
tick_marks = np.arange(len(classes))
|
| 95 |
plt.xticks(tick_marks, classes, color=text_color, fontsize=14) # Adjust text color based on the mode
|
|
@@ -574,16 +575,17 @@ with gr.Blocks(css="""
|
|
| 574 |
with gr.Column():
|
| 575 |
data_percentage_slider = gr.Slider(label="Data Percentage for Training", minimum=10, maximum=100, step=10, value=10)
|
| 576 |
task_complexity_dropdown = gr.Dropdown(label="Task Complexity (Number of Beams)", choices=[16, 32, 64, 128, 256], value=16)
|
| 577 |
-
theme_dropdown = gr.Dropdown(label="Select Theme", choices=['Light', 'Dark'], value='Light')
|
| 578 |
|
| 579 |
with gr.Row():
|
| 580 |
raw_img_bp = gr.Image(label="Raw Channels", type="pil", width=300, height=500)
|
| 581 |
embeddings_img_bp = gr.Image(label="Embeddings", type="pil", width=300, height=500)
|
| 582 |
-
|
|
|
|
| 583 |
# Update the confusion matrices whenever sliders change
|
| 584 |
data_percentage_slider.change(fn=beam_prediction_task, inputs=[data_percentage_slider, task_complexity_dropdown, theme_dropdown], outputs=[raw_img_bp, embeddings_img_bp])
|
| 585 |
task_complexity_dropdown.change(fn=beam_prediction_task, inputs=[data_percentage_slider, task_complexity_dropdown, theme_dropdown], outputs=[raw_img_bp, embeddings_img_bp])
|
| 586 |
-
theme_dropdown.change(fn=beam_prediction_task, inputs=[data_percentage_slider, task_complexity_dropdown, theme_dropdown], outputs=[raw_img_bp, embeddings_img_bp])
|
| 587 |
|
| 588 |
# Add a conclusion section at the bottom
|
| 589 |
gr.Markdown("""
|
|
|
|
| 26 |
raw_cm_path = os.path.join(raw_folder, "confusion_matrix_raw.png")
|
| 27 |
plot_confusion_matrix_beamPred(raw_cm,
|
| 28 |
classes=np.arange(raw_cm.shape[0]),
|
| 29 |
+
title=f"Raw Confusion Matrix\n{data_percentage}% data, {task_complexity} beams",
|
| 30 |
save_path=raw_cm_path,
|
| 31 |
theme=theme)
|
| 32 |
raw_img = Image.open(raw_cm_path)
|
|
|
|
| 39 |
embeddings_cm_path = os.path.join(embeddings_folder, "confusion_matrix_embeddings.png")
|
| 40 |
plot_confusion_matrix_beamPred(embeddings_cm,
|
| 41 |
classes=np.arange(embeddings_cm.shape[0]),
|
| 42 |
+
title=f"Embeddings Confusion Matrix\n{data_percentage}% data, {task_complexity} beams",
|
| 43 |
save_path=embeddings_cm_path,
|
| 44 |
theme=theme)
|
| 45 |
embeddings_img = Image.open(embeddings_cm_path)
|
|
|
|
| 76 |
plt.style.use('dark_background') # Use dark mode styling
|
| 77 |
#text_color = 'white'
|
| 78 |
text_color = 'gray'
|
| 79 |
+
#cmap = 'cividis' # Dark-mode-friendly colormap
|
| 80 |
+
cmap = 'coolwarm'
|
| 81 |
else:
|
| 82 |
plt.style.use('default') # Use default (light) mode styling
|
| 83 |
#text_color = 'black'
|
|
|
|
| 87 |
plt.figure(figsize=(10, 10))
|
| 88 |
|
| 89 |
# Plot the confusion matrix with a colormap compatible for the mode
|
| 90 |
+
sns.heatmap(cm, cmap=cmap, cbar=True, linecolor=text_color ) #, vmin=0, vmax=cm.max(), alpha=0.85)
|
| 91 |
|
| 92 |
# Add F1-score to the title
|
| 93 |
+
plt.title(f"{title}\nF1 Score: {avg_f1:.3f}", color=text_color, fontsize=23)
|
| 94 |
|
| 95 |
tick_marks = np.arange(len(classes))
|
| 96 |
plt.xticks(tick_marks, classes, color=text_color, fontsize=14) # Adjust text color based on the mode
|
|
|
|
| 575 |
with gr.Column():
|
| 576 |
data_percentage_slider = gr.Slider(label="Data Percentage for Training", minimum=10, maximum=100, step=10, value=10)
|
| 577 |
task_complexity_dropdown = gr.Dropdown(label="Task Complexity (Number of Beams)", choices=[16, 32, 64, 128, 256], value=16)
|
| 578 |
+
#theme_dropdown = gr.Dropdown(label="Select Theme", choices=['Light', 'Dark'], value='Light')
|
| 579 |
|
| 580 |
with gr.Row():
|
| 581 |
raw_img_bp = gr.Image(label="Raw Channels", type="pil", width=300, height=500)
|
| 582 |
embeddings_img_bp = gr.Image(label="Embeddings", type="pil", width=300, height=500)
|
| 583 |
+
|
| 584 |
+
theme_dropdown = 'Dark'
|
| 585 |
# Update the confusion matrices whenever sliders change
|
| 586 |
data_percentage_slider.change(fn=beam_prediction_task, inputs=[data_percentage_slider, task_complexity_dropdown, theme_dropdown], outputs=[raw_img_bp, embeddings_img_bp])
|
| 587 |
task_complexity_dropdown.change(fn=beam_prediction_task, inputs=[data_percentage_slider, task_complexity_dropdown, theme_dropdown], outputs=[raw_img_bp, embeddings_img_bp])
|
| 588 |
+
#theme_dropdown.change(fn=beam_prediction_task, inputs=[data_percentage_slider, task_complexity_dropdown, theme_dropdown], outputs=[raw_img_bp, embeddings_img_bp])
|
| 589 |
|
| 590 |
# Add a conclusion section at the bottom
|
| 591 |
gr.Markdown("""
|