Update app.py
Browse files
app.py
CHANGED
|
@@ -697,6 +697,116 @@ with demo:
|
|
| 697 |
|
| 698 |
gr.Markdown("<hr />")
|
| 699 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
|
| 701 |
|
| 702 |
|
|
@@ -1027,18 +1137,6 @@ demo.launch(share=False)
|
|
| 1027 |
|
| 1028 |
# gr.Markdown("<hr />")
|
| 1029 |
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
# ########################## Encrypt Data ##########################
|
| 1043 |
|
| 1044 |
# gr.Markdown(
|
|
@@ -1149,6 +1247,22 @@ demo.launch(share=False)
|
|
| 1149 |
|
| 1150 |
# gr.Markdown("<hr />")
|
| 1151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1152 |
# ########################## Model Prediction ##########################
|
| 1153 |
|
| 1154 |
# gr.Markdown("## Step 3: Run the FHE evaluation.")
|
|
|
|
| 697 |
|
| 698 |
gr.Markdown("<hr />")
|
| 699 |
|
| 700 |
+
########################## Encrypt Data ##########################
|
| 701 |
+
|
| 702 |
+
gr.Markdown(
|
| 703 |
+
"## Step 2: Make your purchase\n\n"
|
| 704 |
+
"""
|
| 705 |
+
🛍️ It's time to shop! To simulate your latest purchase, please provide the details of your most recent transaction.
|
| 706 |
+
|
| 707 |
+
If you don't have an idea, you can pre-fill with an example of fraud or non-fraud.
|
| 708 |
+
"""
|
| 709 |
+
)
|
| 710 |
+
|
| 711 |
+
def prefill_fraud():
|
| 712 |
+
return 34, 50, 3, False, False, False, True
|
| 713 |
+
|
| 714 |
+
def prefill_no_fraud():
|
| 715 |
+
return 12, 2, 0.7, True, False, True, False
|
| 716 |
+
|
| 717 |
+
with gr.Row():
|
| 718 |
+
prefill_button = gr.Button("Exemple Fraud")
|
| 719 |
+
prefill_button_no = gr.Button("Exemple No-Fraud")
|
| 720 |
+
|
| 721 |
+
with gr.Row():
|
| 722 |
+
with gr.Column():
|
| 723 |
+
distance_home = gr.Number(
|
| 724 |
+
minimum=float(0),
|
| 725 |
+
maximum=float(22000),
|
| 726 |
+
step=1,
|
| 727 |
+
value=10,
|
| 728 |
+
label="Distance from Home",
|
| 729 |
+
info="How far was the purchase from your home (in km)?"
|
| 730 |
+
)
|
| 731 |
+
distance_last = gr.Number(
|
| 732 |
+
minimum=float(0),
|
| 733 |
+
maximum=float(22000),
|
| 734 |
+
step=1,
|
| 735 |
+
value=1,
|
| 736 |
+
label="Distance from Last Transaction",
|
| 737 |
+
info="Distance between this purchase and the last one (in km)?"
|
| 738 |
+
)
|
| 739 |
+
ratio = gr.Number(
|
| 740 |
+
minimum=float(0),
|
| 741 |
+
maximum=float(10000),
|
| 742 |
+
step=0.1,
|
| 743 |
+
value=1,
|
| 744 |
+
label="Ratio to Median Purchase Price",
|
| 745 |
+
info="Purchase ratio compared to your average purchase",
|
| 746 |
+
)
|
| 747 |
+
repeat_retailer = gr.Checkbox(
|
| 748 |
+
label="Repeat Retailer",
|
| 749 |
+
info="Check if you are purchasing from the same retailer as your last transaction"
|
| 750 |
+
)
|
| 751 |
+
used_chip = gr.Checkbox(
|
| 752 |
+
label="Used Chip",
|
| 753 |
+
info="Check if you used a chip card for this transaction"
|
| 754 |
+
)
|
| 755 |
+
used_pin_number = gr.Checkbox(
|
| 756 |
+
label="Used Pin Number",
|
| 757 |
+
info="Check if you used your PIN number during the transaction"
|
| 758 |
+
)
|
| 759 |
+
online = gr.Checkbox(
|
| 760 |
+
label="Online Order",
|
| 761 |
+
info="Check if you made your purchase online"
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
prefill_button.click(
|
| 766 |
+
fn=prefill_fraud,
|
| 767 |
+
inputs=[],
|
| 768 |
+
outputs=[
|
| 769 |
+
distance_home,
|
| 770 |
+
distance_last,
|
| 771 |
+
ratio,
|
| 772 |
+
repeat_retailer,
|
| 773 |
+
used_chip,
|
| 774 |
+
used_pin_number,
|
| 775 |
+
online
|
| 776 |
+
]
|
| 777 |
+
)
|
| 778 |
+
|
| 779 |
+
prefill_button_no.click(
|
| 780 |
+
fn=prefill_no_fraud,
|
| 781 |
+
inputs=[],
|
| 782 |
+
outputs=[
|
| 783 |
+
distance_home,
|
| 784 |
+
distance_last,
|
| 785 |
+
ratio,
|
| 786 |
+
repeat_retailer,
|
| 787 |
+
used_chip,
|
| 788 |
+
used_pin_number,
|
| 789 |
+
online
|
| 790 |
+
]
|
| 791 |
+
)
|
| 792 |
+
|
| 793 |
+
with gr.Row():
|
| 794 |
+
with gr.Column(scale=2):
|
| 795 |
+
encrypt_button_applicant = gr.Button("Encrypt the inputs and send to server.")
|
| 796 |
+
|
| 797 |
+
encrypted_input_applicant = gr.Textbox(
|
| 798 |
+
label="Encrypted input representation:", max_lines=2, interactive=False
|
| 799 |
+
)
|
| 800 |
+
|
| 801 |
+
encrypt_button_applicant.click(
|
| 802 |
+
pre_process_encrypt_send_purchase,
|
| 803 |
+
inputs=[distance_home, distance_last, ratio, repeat_retailer, used_chip, used_pin_number, \
|
| 804 |
+
online],
|
| 805 |
+
outputs=[encrypted_input_applicant, encrypt_button_applicant],
|
| 806 |
+
)
|
| 807 |
+
|
| 808 |
+
gr.Markdown("<hr />")
|
| 809 |
+
|
| 810 |
|
| 811 |
|
| 812 |
|
|
|
|
| 1137 |
|
| 1138 |
# gr.Markdown("<hr />")
|
| 1139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1140 |
# ########################## Encrypt Data ##########################
|
| 1141 |
|
| 1142 |
# gr.Markdown(
|
|
|
|
| 1247 |
|
| 1248 |
# gr.Markdown("<hr />")
|
| 1249 |
|
| 1250 |
+
|
| 1251 |
+
|
| 1252 |
+
|
| 1253 |
+
|
| 1254 |
+
|
| 1255 |
+
|
| 1256 |
+
|
| 1257 |
+
|
| 1258 |
+
|
| 1259 |
+
|
| 1260 |
+
|
| 1261 |
+
|
| 1262 |
+
|
| 1263 |
+
|
| 1264 |
+
|
| 1265 |
+
|
| 1266 |
# ########################## Model Prediction ##########################
|
| 1267 |
|
| 1268 |
# gr.Markdown("## Step 3: Run the FHE evaluation.")
|