Update app.py
Browse files
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 |
"""
|
@@ -18,19 +24,23 @@ def key_generated():
|
|
18 |
print("Keys have been generated ✅")
|
19 |
return {gen_key_btn: gr.update(value="Keys have been generated ✅")}
|
20 |
|
21 |
-
|
22 |
demo = gr.Blocks(css=".markdown-body { font-size: 18px; }")
|
23 |
|
24 |
with demo:
|
|
|
|
|
|
|
25 |
gr.Markdown(
|
26 |
-
"""
|
27 |
<div style="display: flex; justify-content: center; align-items: center;">
|
28 |
-
<img style="margin-right: 50px;" width=200 src="
|
29 |
-
<img width=200 src="
|
30 |
</div>
|
31 |
"""
|
32 |
)
|
33 |
|
|
|
|
|
34 |
gr.Markdown(
|
35 |
"""
|
36 |
<h1 style="text-align: center;">Fraud Detection with FHE Model</h1>
|
@@ -93,10 +103,11 @@ with demo:
|
|
93 |
"""
|
94 |
)
|
95 |
|
|
|
96 |
gr.Markdown(
|
97 |
-
"""
|
98 |
<p align="center">
|
99 |
-
<img width="75%" height="30%" src="
|
100 |
</p>
|
101 |
"""
|
102 |
)
|
@@ -120,7 +131,7 @@ with demo:
|
|
120 |
key_generated,
|
121 |
inputs=[],
|
122 |
outputs=[gen_key_btn],
|
123 |
-
)
|
124 |
|
125 |
gr.Markdown("<hr />")
|
126 |
|
@@ -253,6 +264,7 @@ with demo:
|
|
253 |
label="Total FHE execution time (in seconds):", max_lines=1, interactive=False
|
254 |
)
|
255 |
|
|
|
256 |
execute_fhe_button.click(predict, outputs=[fhe_execution_time, execute_fhe_button])
|
257 |
|
258 |
gr.Markdown("<hr />")
|
@@ -274,6 +286,7 @@ with demo:
|
|
274 |
decrypt_prediction,
|
275 |
outputs=[prediction_output, get_output_button],
|
276 |
)
|
|
|
277 |
|
278 |
gr.Markdown(
|
279 |
"""
|
@@ -288,4 +301,4 @@ with demo:
|
|
288 |
)
|
289 |
|
290 |
if __name__ == "__main__":
|
291 |
-
demo.launch()
|
|
|
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 |
"""
|
|
|
24 |
print("Keys have been generated ✅")
|
25 |
return {gen_key_btn: gr.update(value="Keys have been generated ✅")}
|
26 |
|
|
|
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 |
)
|
|
|
131 |
key_generated,
|
132 |
inputs=[],
|
133 |
outputs=[gen_key_btn],
|
134 |
+
)#547
|
135 |
|
136 |
gr.Markdown("<hr />")
|
137 |
|
|
|
264 |
label="Total FHE execution time (in seconds):", max_lines=1, interactive=False
|
265 |
)
|
266 |
|
267 |
+
# Button to send the encodings to the server using post method
|
268 |
execute_fhe_button.click(predict, outputs=[fhe_execution_time, execute_fhe_button])
|
269 |
|
270 |
gr.Markdown("<hr />")
|
|
|
286 |
decrypt_prediction,
|
287 |
outputs=[prediction_output, get_output_button],
|
288 |
)
|
289 |
+
|
290 |
|
291 |
gr.Markdown(
|
292 |
"""
|
|
|
301 |
)
|
302 |
|
303 |
if __name__ == "__main__":
|
304 |
+
demo.launch()
|