2021-07-29 02:21:28 +08:00
|
|
|
import random
|
|
|
|
|
2022-01-21 21:44:12 +08:00
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
import gradio as gr
|
|
|
|
|
2021-08-10 05:16:29 +08:00
|
|
|
|
2021-07-29 02:21:28 +08:00
|
|
|
def fraud_detector(card_activity, categories, sensitivity):
|
|
|
|
activity_range = random.randint(0, 100)
|
2022-01-21 21:44:12 +08:00
|
|
|
drop_columns = [
|
|
|
|
column for column in ["retail", "food", "other"] if column not in categories
|
|
|
|
]
|
2021-08-10 05:16:29 +08:00
|
|
|
if len(drop_columns):
|
|
|
|
card_activity.drop(columns=drop_columns, inplace=True)
|
2022-01-21 21:44:12 +08:00
|
|
|
return (
|
|
|
|
card_activity,
|
|
|
|
card_activity,
|
|
|
|
{"fraud": activity_range / 100.0, "not fraud": 1 - activity_range / 100.0},
|
|
|
|
)
|
2021-08-10 05:16:29 +08:00
|
|
|
|
2021-07-29 02:21:28 +08:00
|
|
|
|
2022-01-21 21:44:12 +08:00
|
|
|
iface = gr.Interface(
|
|
|
|
fraud_detector,
|
|
|
|
[
|
|
|
|
gr.inputs.Timeseries(x="time", y=["retail", "food", "other"]),
|
|
|
|
gr.inputs.CheckboxGroup(
|
|
|
|
["retail", "food", "other"], default=["retail", "food", "other"]
|
|
|
|
),
|
|
|
|
gr.inputs.Slider(1, 3),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"dataframe",
|
|
|
|
gr.outputs.Timeseries(x="time", y=["retail", "food", "other"]),
|
|
|
|
gr.outputs.Label(label="Fraud Level"),
|
|
|
|
],
|
|
|
|
)
|
2021-07-29 02:21:28 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
iface.launch()
|