Kieran Fraser commited on
Commit
eda40cc
1 Parent(s): b88aa2b

Added blue evaluate button

Browse files

Signed-off-by: Kieran Fraser <[email protected]>

Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -41,9 +41,7 @@ css = """
41
  .center-text { text-align: center !important }
42
  .larger-gap { gap: 100px !important; }
43
  .symbols { text-align: center !important; margin: auto !important; }
44
- div.svelte-15lo0d8>*, div.svelte-15lo0d8>.form > * {
45
- min-width: 0px !important;
46
- }
47
  .eval-bt { background-color: #3b74f4; color: white; }
48
  """
49
 
@@ -224,13 +222,13 @@ with gr.Blocks(css=css, theme='Tshackelton/IBMPlex-DenseReadable') as demo:
224
 
225
 
226
  with gr.Row(elem_classes=["larger-gap", "custom-text"]):
227
- with gr.Column(scale=1):
228
  gr.Markdown('''<p style="font-size: 20px; text-align: justify">ℹ️ First lets set the scene. You have a dataset of images, such as CIFAR-10.</p>''')
229
  gr.Markdown('''<p style="font-size: 18px; text-align: justify"><i>Note: CIFAR-10 images are low resolution images which span 10 different categories as shown.</i></p>''')
230
  gr.Markdown('''<p style="font-size: 20px; text-align: justify">ℹ️ Your goal is to have an AI model capable of classifying these images. So you
231
  train a model on this dataset, or use a pre-trained model from Hugging Face,
232
  such as Meta's Distilled Data-efficient Image Transformer.</p>''')
233
- with gr.Column(scale=1):
234
  gr.Markdown('''
235
  <p style="font-size: 20px;"><b>Hugging Face dataset:</b>
236
  <a href="https://huggingface.co/datasets/cifar10" target="_blank">CIFAR-10</a></p>
@@ -244,7 +242,7 @@ with gr.Blocks(css=css, theme='Tshackelton/IBMPlex-DenseReadable') as demo:
244
  <br/>
245
  <p style="font-size: 20px;">👀 take a look at the sample images from the CIFAR-10 dataset and their respective labels.</p>
246
  ''')
247
- with gr.Column(scale=1):
248
  gr.Gallery(label="CIFAR-10", preview=True, value=sample_CIFAR10(), height=420)
249
 
250
  gr.Markdown('''<hr/>''')
@@ -270,7 +268,7 @@ with gr.Blocks(css=css, theme='Tshackelton/IBMPlex-DenseReadable') as demo:
270
  max_iter = gr.Slider(minimum=1, maximum=10, label="Max iterations", value=4)
271
  eps = gr.Slider(minimum=0.0001, maximum=1, label="Epslion", value=0.3)
272
  eps_steps = gr.Slider(minimum=0.0001, maximum=1, label="Epsilon steps", value=0.03)
273
- bt_eval_pgd = gr.Button("Evaluate", elem_classes="eval-bt")
274
 
275
  # Evaluation Output. Visualisations of success/failures of running evaluation attacks.
276
  with gr.Column(scale=5):
@@ -280,12 +278,12 @@ with gr.Blocks(css=css, theme='Tshackelton/IBMPlex-DenseReadable') as demo:
280
  original_gallery = gr.Gallery(label="Original", preview=False, show_download_button=True)
281
  benign_output = gr.Label(num_top_classes=3, visible=False)
282
  clean_accuracy = gr.Number(label="Clean Accuracy", precision=2)
283
- with gr.Column(scale=1, min_width='0px', elem_classes='symbols'):
284
  gr.Markdown('''➕''')
285
  with gr.Column(scale=10):
286
- gr.Markdown('''<p style="font-size: 18px"><i>Visual representation of the calculated perturbations for attacking the model (black pixels indicate little to no perturbation).</i></p>''')
287
  delta_gallery = gr.Gallery(label="Added perturbation", preview=False, show_download_button=True)
288
- with gr.Column(scale=1, min_width='0px'):
289
  gr.Markdown('''🟰''', elem_classes='symbols')
290
  with gr.Column(scale=10):
291
  gr.Markdown('''<p style="font-size: 18px"><i>The original image (with optimized perturbations applied) gives us an adversarial image which fools the model.</i></p>''')
@@ -313,7 +311,7 @@ with gr.Blocks(css=css, theme='Tshackelton/IBMPlex-DenseReadable') as demo:
313
  y_location = gr.Slider(minimum=1, maximum=32, label="Location (y)", value=1)
314
  patch_height = gr.Slider(minimum=1, maximum=32, label="Patch height", value=12)
315
  patch_width = gr.Slider(minimum=1, maximum=32, label="Patch width", value=12)
316
- eval_btn_patch = gr.Button("Evaluate", elem_classes="eval-bt")
317
 
318
  # Evaluation Output. Visualisations of success/failures of running evaluation attacks.
319
  with gr.Column(scale=3):
@@ -323,14 +321,14 @@ with gr.Blocks(css=css, theme='Tshackelton/IBMPlex-DenseReadable') as demo:
323
  original_gallery = gr.Gallery(label="Original", preview=False, show_download_button=True)
324
  clean_accuracy = gr.Number(label="Clean Accuracy", precision=2)
325
 
326
- with gr.Column(scale=1, min_width='0px', elem_classes='symbols'):
327
  gr.Markdown('''➕''')
328
 
329
  with gr.Column(scale=10):
330
  gr.Markdown('''<p style="font-size: 18px"><i>Visual representation of the optimized patch for attacking the model.</i></p><br><br>''')
331
  delta_gallery = gr.Gallery(label="Patches", preview=True, show_download_button=True)
332
 
333
- with gr.Column(scale=1, min_width='0px'):
334
  gr.Markdown('''🟰''', elem_classes='symbols')
335
 
336
  with gr.Column(scale=10):
 
41
  .center-text { text-align: center !important }
42
  .larger-gap { gap: 100px !important; }
43
  .symbols { text-align: center !important; margin: auto !important; }
44
+ .cust-width { min-width: 250px !important;}
 
 
45
  .eval-bt { background-color: #3b74f4; color: white; }
46
  """
47
 
 
222
 
223
 
224
  with gr.Row(elem_classes=["larger-gap", "custom-text"]):
225
+ with gr.Column(scale=1, elem_classes="cust-width"):
226
  gr.Markdown('''<p style="font-size: 20px; text-align: justify">ℹ️ First lets set the scene. You have a dataset of images, such as CIFAR-10.</p>''')
227
  gr.Markdown('''<p style="font-size: 18px; text-align: justify"><i>Note: CIFAR-10 images are low resolution images which span 10 different categories as shown.</i></p>''')
228
  gr.Markdown('''<p style="font-size: 20px; text-align: justify">ℹ️ Your goal is to have an AI model capable of classifying these images. So you
229
  train a model on this dataset, or use a pre-trained model from Hugging Face,
230
  such as Meta's Distilled Data-efficient Image Transformer.</p>''')
231
+ with gr.Column(scale=1, elem_classes="cust-width"):
232
  gr.Markdown('''
233
  <p style="font-size: 20px;"><b>Hugging Face dataset:</b>
234
  <a href="https://huggingface.co/datasets/cifar10" target="_blank">CIFAR-10</a></p>
 
242
  <br/>
243
  <p style="font-size: 20px;">👀 take a look at the sample images from the CIFAR-10 dataset and their respective labels.</p>
244
  ''')
245
+ with gr.Column(scale=1, elem_classes="cust-width"):
246
  gr.Gallery(label="CIFAR-10", preview=True, value=sample_CIFAR10(), height=420)
247
 
248
  gr.Markdown('''<hr/>''')
 
268
  max_iter = gr.Slider(minimum=1, maximum=10, label="Max iterations", value=4)
269
  eps = gr.Slider(minimum=0.0001, maximum=1, label="Epslion", value=0.3)
270
  eps_steps = gr.Slider(minimum=0.0001, maximum=1, label="Epsilon steps", value=0.03)
271
+ bt_eval_pgd = gr.Button("Evaluate", elem_classes="eval-bt")
272
 
273
  # Evaluation Output. Visualisations of success/failures of running evaluation attacks.
274
  with gr.Column(scale=5):
 
278
  original_gallery = gr.Gallery(label="Original", preview=False, show_download_button=True)
279
  benign_output = gr.Label(num_top_classes=3, visible=False)
280
  clean_accuracy = gr.Number(label="Clean Accuracy", precision=2)
281
+ with gr.Column(scale=1, min_width=0, elem_classes='symbols'):
282
  gr.Markdown('''➕''')
283
  with gr.Column(scale=10):
284
+ gr.Markdown('''<p style="font-size: 18px"><i>Visual representation of the calculated perturbations for attacking the model.</i></p><br>''')
285
  delta_gallery = gr.Gallery(label="Added perturbation", preview=False, show_download_button=True)
286
+ with gr.Column(scale=1, min_width=0):
287
  gr.Markdown('''🟰''', elem_classes='symbols')
288
  with gr.Column(scale=10):
289
  gr.Markdown('''<p style="font-size: 18px"><i>The original image (with optimized perturbations applied) gives us an adversarial image which fools the model.</i></p>''')
 
311
  y_location = gr.Slider(minimum=1, maximum=32, label="Location (y)", value=1)
312
  patch_height = gr.Slider(minimum=1, maximum=32, label="Patch height", value=12)
313
  patch_width = gr.Slider(minimum=1, maximum=32, label="Patch width", value=12)
314
+ eval_btn_patch = gr.Button("Evaluate", elem_classes="eval-bt")
315
 
316
  # Evaluation Output. Visualisations of success/failures of running evaluation attacks.
317
  with gr.Column(scale=3):
 
321
  original_gallery = gr.Gallery(label="Original", preview=False, show_download_button=True)
322
  clean_accuracy = gr.Number(label="Clean Accuracy", precision=2)
323
 
324
+ with gr.Column(scale=1, min_width=0, elem_classes='symbols'):
325
  gr.Markdown('''➕''')
326
 
327
  with gr.Column(scale=10):
328
  gr.Markdown('''<p style="font-size: 18px"><i>Visual representation of the optimized patch for attacking the model.</i></p><br><br>''')
329
  delta_gallery = gr.Gallery(label="Patches", preview=True, show_download_button=True)
330
 
331
+ with gr.Column(scale=1, min_width=0):
332
  gr.Markdown('''🟰''', elem_classes='symbols')
333
 
334
  with gr.Column(scale=10):