Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import tensorflow as tf
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
import seaborn as sns
|
6 |
from tensorflow.keras.models import load_model
|
7 |
from tensorflow.keras.utils import to_categorical
|
8 |
from sklearn.metrics import confusion_matrix
|
@@ -74,21 +72,35 @@ def gradio_mask(image, steps, increment):
|
|
74 |
modified_image, original_label, predicted_label = progressively_mask_image(image, steps, increment)
|
75 |
return modified_image, f"Original Label: {original_label}, New Label: {predicted_label}"
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import tensorflow as tf
|
|
|
|
|
4 |
from tensorflow.keras.models import load_model
|
5 |
from tensorflow.keras.utils import to_categorical
|
6 |
from sklearn.metrics import confusion_matrix
|
|
|
72 |
modified_image, original_label, predicted_label = progressively_mask_image(image, steps, increment)
|
73 |
return modified_image, f"Original Label: {original_label}, New Label: {predicted_label}"
|
74 |
|
75 |
+
def create_interface():
|
76 |
+
card_html = """
|
77 |
+
<div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; text-align: center; margin-bottom: 20px;">
|
78 |
+
<h1 style="font-family: Arial, sans-serif; color: #333;">Attribution Based Confidence Metric for Neural Networks</h1>
|
79 |
+
<h2 style="font-family: Arial, sans-serif; color: #555;">Steven Fernandes, Ph.D.</h2>
|
80 |
+
</div>
|
81 |
+
"""
|
82 |
+
|
83 |
+
image_input = gr.Image(image_mode='L', label="Input Image")
|
84 |
+
steps_input = gr.Slider(minimum=1, maximum=100, label="Steps", step=1, value=100)
|
85 |
+
increment_input = gr.Slider(minimum=1, maximum=20, label="Increment", step=1, value=5)
|
86 |
+
|
87 |
+
with gr.Blocks() as demo:
|
88 |
+
gr.HTML(card_html)
|
89 |
+
gr.Interface(
|
90 |
+
fn=gradio_mask,
|
91 |
+
inputs=[image_input, steps_input, increment_input],
|
92 |
+
outputs=[
|
93 |
+
gr.Image(image_mode='L', label="Output Image"),
|
94 |
+
gr.Textbox(label="Prediction Details")
|
95 |
+
],
|
96 |
+
title="Progressive Masking",
|
97 |
+
description="Upload an image of a digit and observe how masking affects the model's prediction.",
|
98 |
+
examples=mnist_examples,
|
99 |
+
allow_flagging="never"
|
100 |
+
).launch()
|
101 |
+
|
102 |
+
def main():
|
103 |
+
create_interface()
|
104 |
+
|
105 |
+
if __name__ == "__main__":
|
106 |
+
main()
|