Last commit not found
import gradio as gr | |
from predictor import predict | |
def make_prediction(distance_from_home, distance_from_last_transaction, | |
ratio_to_median_purchase_price, repeat_retailer, | |
used_chip, used_pin_number, online_order): | |
""" | |
Prepares user input data and performs a local prediction. | |
Args: | |
distance_from_home (float): Distance from home. | |
distance_from_last_transaction (float): Distance from the last transaction. | |
ratio_to_median_purchase_price (float): Ratio to the median purchase price. | |
repeat_retailer (bool): Repeated retailer. | |
used_chip (bool): Used chip. | |
used_pin_number (bool): Used PIN number. | |
online_order (bool): Online order. | |
Returns: | |
str: Prediction result ("Fraudulent" or "Non-fraudulent"). | |
""" | |
try: | |
input_data = { | |
"distance_from_home": distance_from_home, | |
"distance_from_last_transaction": distance_from_last_transaction, | |
"ratio_to_median_purchase_price": ratio_to_median_purchase_price, | |
"repeat_retailer": int(repeat_retailer), | |
"used_chip": int(used_chip), | |
"used_pin_number": int(used_pin_number), | |
"online_order": int(online_order), | |
} | |
return predict(input_data) | |
except Exception as e: | |
return f"Unexpected error: {e}" | |
# Gradio user interface | |
iface = gr.Interface( | |
fn=make_prediction, | |
inputs=[ | |
gr.Number(label="Distance from Home"), | |
gr.Number(label="Distance from Last Transaction"), | |
gr.Number(label="Ratio to Median Purchase Price"), | |
gr.Checkbox(label="Repeat Retailer"), | |
gr.Checkbox(label="Used Chip"), | |
gr.Checkbox(label="Used PIN Number"), | |
gr.Checkbox(label="Online Order"), | |
], | |
outputs=gr.Textbox(label="Output"), | |
title="Fraud Detection with Local FHE Model", | |
description="Local interface using a compiled FHE model to detect fraud." | |
) | |
if __name__ == "__main__": | |
iface.launch() | |