QiaoNPC commited on
Commit
73e7a75
1 Parent(s): 7349f7c

Update app.py & readme.md

Browse files
Files changed (2) hide show
  1. README.md +12 -1
  2. app.py +76 -6
README.md CHANGED
@@ -9,4 +9,15 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
+
14
+ # PwnAI Demo
15
+
16
+ ## Overview
17
+ PwnAI is an educational event that explores adversarial machine learning techniques, specifically focusing on attacking Image Classifiers and Language Model (LM) Prompt Injections. This repository contains a demo showcasing how adversarial attacks can be applied to image classifiers.
18
+
19
+ ## Demo Description
20
+ The demo includes two example pictures that appear very similar but are classified differently. Users can interact with the demo by submitting both pictures for inference, allowing them to observe how the machine learning model's classification can be manipulated through adversarial attacks. Users can also submit their own pictures to play around.
21
+
22
+ ## Performance Note
23
+ Please note that this demo runs on a free-tier CPU, so its performance may be slow.
app.py CHANGED
@@ -27,11 +27,81 @@ def predict(img):
27
  label_confidences = {label: prob for label, prob in zip(top_10_labels, top_10_probabilities)}
28
  return label_confidences
29
 
30
- demo = gr.Interface(
31
- fn=predict,
32
- inputs=gr.Image(),
33
- outputs=gr.Label(),
34
- examples=examples
35
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  demo.launch()
 
27
  label_confidences = {label: prob for label, prob in zip(top_10_labels, top_10_probabilities)}
28
  return label_confidences
29
 
30
+ css = '''
31
+ .gradio-container {
32
+ width: 85% !important;
33
+ }
34
+ h1 {
35
+ width: 100% !important;
36
+ }
37
+ p {
38
+ margin-left: 30px !important;
39
+ margin-right: 30px !important;
40
+ font-size: 1.1rem !important;
41
+ }
42
+ '''
43
+
44
+ title = r"""
45
+ <h1>GDSC: PwnAI Image Classifier Demo</h1>
46
+ """
47
+ description = r"""
48
+ <p>PwnAI is an educational event that explores adversarial machine learning. It aims to help students learn about LLM Prompt Injection and Fooling Image Classifiers.</p>
49
+ <p>In this demo, there are two example pictures. They may look very similar to us, but they are classified differently. Try it out yourself by submitting both pictures for inference and observing the results.</p>
50
+ <p>Try it out yourself by experimenting with the image on the left to see if you can cause a misclassification.</p>
51
+ <h2>What to Expect</h2>
52
+ <p>Participants will explore these concepts through interactive demos and hands-on workshops, gaining insights into applying adversarial attacks to machine learning models.</p>
53
+ <h2>NOTE</h2>
54
+ <p>This demo runs on a free-tier CPU, so its performance is slow.</p>
55
+ <h2>What can this AI Classify</h2>
56
+ <p>1. Bread</p>
57
+ <p>2. Dairy</p>
58
+ <p>3. Dessert</p>
59
+ <p>4. Egg</p>
60
+ <p>5. Fried Food</p>
61
+ <p>6. Fruit</p>
62
+ <p>7. Meat</p>
63
+ <p>8. Noodles</p>
64
+ <p>9. Rice</p>
65
+ <p>10. Seafood</p>
66
+ <p>11. Soup</p>
67
+ <p>12. Vegetable</p>
68
+ """
69
+
70
+ Ending = r"""
71
+ <p>Woahhhh. Is this steganography???? Who knows? Come for the event to find out!</p>
72
+ """
73
+
74
+ Footer = r"""
75
+ ---
76
+ Challenge Created By Chai Cheng Xun
77
+ """
78
+
79
+ with gr.Blocks(css=css, title="PwnAI: Image Classifier Demo") as demo:
80
+ gr.Markdown(title)
81
+ gr.Markdown(description)
82
+
83
+ with gr.Row():
84
+ with gr.Column():
85
+ img_file = gr.Image(label="Upload a photo to be classfied")
86
+ submit = gr.Button("Submit", variant="primary")
87
+
88
+
89
+ with gr.Column():
90
+ output = gr.Label()
91
+
92
+ submit.click(
93
+ fn=predict,
94
+ inputs=img_file,
95
+ outputs=output,
96
+ )
97
+
98
+
99
+ gr.Examples(
100
+ examples=examples,
101
+ inputs=[img_file],
102
+ )
103
+
104
+ gr.Markdown(Ending)
105
+ gr.Markdown(Footer)
106
 
107
  demo.launch()