Update app.py (#6)
Browse files- Update app.py (0ea49188140ba7112a5c5c6074b3523e3c50d078)
Co-authored-by: Sandro Ferroni <[email protected]>
app.py
CHANGED
@@ -1,5 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
from predictor import predict, key_already_generated, pre_process_encrypt_send_purchase, decrypt_prediction
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def key_generated():
|
5 |
"""
|
@@ -21,15 +27,20 @@ def key_generated():
|
|
21 |
demo = gr.Blocks(css=".markdown-body { font-size: 18px; }")
|
22 |
|
23 |
with demo:
|
|
|
|
|
|
|
24 |
gr.Markdown(
|
25 |
-
"""
|
26 |
<div style="display: flex; justify-content: center; align-items: center;">
|
27 |
-
<img style="margin-right: 50px;" width=200 src="
|
28 |
-
<img width=200 src="
|
29 |
</div>
|
30 |
"""
|
31 |
)
|
32 |
|
|
|
|
|
33 |
gr.Markdown(
|
34 |
"""
|
35 |
<h1 style="text-align: center;">Fraud Detection with FHE Model</h1>
|
@@ -92,10 +103,11 @@ with demo:
|
|
92 |
"""
|
93 |
)
|
94 |
|
|
|
95 |
gr.Markdown(
|
96 |
-
"""
|
97 |
<p align="center">
|
98 |
-
<img width="75%" height="30%" src="
|
99 |
</p>
|
100 |
"""
|
101 |
)
|
@@ -127,10 +139,23 @@ with demo:
|
|
127 |
|
128 |
gr.Markdown(
|
129 |
"## Step 2: Make your purchase\n\n"
|
130 |
-
"""
|
|
|
|
|
|
|
131 |
"""
|
132 |
)
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
with gr.Row():
|
135 |
with gr.Column():
|
136 |
distance_home = gr.Slider(
|
@@ -174,6 +199,35 @@ with demo:
|
|
174 |
info="Check if you made your purchase online"
|
175 |
)
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
with gr.Row():
|
178 |
with gr.Column(scale=2):
|
179 |
encrypt_button_applicant = gr.Button("Encrypt the inputs and send to server.")
|
|
|
1 |
import gradio as gr
|
2 |
from predictor import predict, key_already_generated, pre_process_encrypt_send_purchase, decrypt_prediction
|
3 |
+
import base64
|
4 |
+
|
5 |
+
def encode_image_to_base64(image_path):
|
6 |
+
with open(image_path, "rb") as image_file:
|
7 |
+
return base64.b64encode(image_file.read()).decode("utf-8")
|
8 |
+
|
9 |
|
10 |
def key_generated():
|
11 |
"""
|
|
|
27 |
demo = gr.Blocks(css=".markdown-body { font-size: 18px; }")
|
28 |
|
29 |
with demo:
|
30 |
+
zama_base64 = encode_image_to_base64("./Img/zama.png")
|
31 |
+
epita_base64 = encode_image_to_base64("./Img/Epita.png")
|
32 |
+
|
33 |
gr.Markdown(
|
34 |
+
f"""
|
35 |
<div style="display: flex; justify-content: center; align-items: center;">
|
36 |
+
<img style="margin-right: 50px;" width=200 src="data:image/png;base64,{zama_base64}">
|
37 |
+
<img width=200 src="data:image/png;base64,{epita_base64}">
|
38 |
</div>
|
39 |
"""
|
40 |
)
|
41 |
|
42 |
+
|
43 |
+
|
44 |
gr.Markdown(
|
45 |
"""
|
46 |
<h1 style="text-align: center;">Fraud Detection with FHE Model</h1>
|
|
|
103 |
"""
|
104 |
)
|
105 |
|
106 |
+
schema_base64 = encode_image_to_base64("./Img/schema.png")
|
107 |
gr.Markdown(
|
108 |
+
f"""
|
109 |
<p align="center">
|
110 |
+
<img width="75%" height="30%" src="data:image/png;base64,{schema_base64}">
|
111 |
</p>
|
112 |
"""
|
113 |
)
|
|
|
139 |
|
140 |
gr.Markdown(
|
141 |
"## Step 2: Make your purchase\n\n"
|
142 |
+
"""
|
143 |
+
🛍️ It's time to shop! To simulate your latest purchase, please provide the details of your most recent transaction.
|
144 |
+
|
145 |
+
If you don't have an idea, you can pre-fill with an example of fraud or non-fraud.
|
146 |
"""
|
147 |
)
|
148 |
|
149 |
+
def prefill_fraud():
|
150 |
+
return 34, 50, 3, False, False, False, True
|
151 |
+
|
152 |
+
def prefill_no_fraud():
|
153 |
+
return 12, 2, 0.7, True, False, True, False
|
154 |
+
|
155 |
+
with gr.Row():
|
156 |
+
prefill_button = gr.Button("Exemple Fraud")
|
157 |
+
prefill_button_no = gr.Button("Exemple No-Fraud")
|
158 |
+
|
159 |
with gr.Row():
|
160 |
with gr.Column():
|
161 |
distance_home = gr.Slider(
|
|
|
199 |
info="Check if you made your purchase online"
|
200 |
)
|
201 |
|
202 |
+
|
203 |
+
prefill_button.click(
|
204 |
+
fn=prefill_fraud,
|
205 |
+
inputs=[],
|
206 |
+
outputs=[
|
207 |
+
distance_home,
|
208 |
+
distance_last,
|
209 |
+
ratio,
|
210 |
+
repeat_retailer,
|
211 |
+
used_chip,
|
212 |
+
used_pin_number,
|
213 |
+
online
|
214 |
+
]
|
215 |
+
)
|
216 |
+
|
217 |
+
prefill_button_no.click(
|
218 |
+
fn=prefill_no_fraud,
|
219 |
+
inputs=[],
|
220 |
+
outputs=[
|
221 |
+
distance_home,
|
222 |
+
distance_last,
|
223 |
+
ratio,
|
224 |
+
repeat_retailer,
|
225 |
+
used_chip,
|
226 |
+
used_pin_number,
|
227 |
+
online
|
228 |
+
]
|
229 |
+
)
|
230 |
+
|
231 |
with gr.Row():
|
232 |
with gr.Column(scale=2):
|
233 |
encrypt_button_applicant = gr.Button("Encrypt the inputs and send to server.")
|