Spaces:
Sleeping
Sleeping
Update prediction.py
Browse files- prediction.py +70 -3
prediction.py
CHANGED
@@ -1,7 +1,74 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
import joblib
|
4 |
-
import json
|
5 |
|
6 |
def app():
|
7 |
-
st.title(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
import joblib
|
|
|
4 |
|
5 |
def app():
|
6 |
+
st.title("Transaction Data Input")
|
7 |
+
st.write("Choose to upload a CSV file or manually input transaction data.")
|
8 |
+
|
9 |
+
# Load pre-trained model
|
10 |
+
model = joblib.load('model.pkl')
|
11 |
+
|
12 |
+
# Option to choose upload or manual input
|
13 |
+
option = st.radio("Select input method:", ("Upload CSV", "Manual Input"))
|
14 |
+
|
15 |
+
if option == "Upload CSV":
|
16 |
+
# Option to upload a CSV file
|
17 |
+
file_upload = st.file_uploader("Upload CSV", type=["csv"])
|
18 |
+
|
19 |
+
if file_upload is not None:
|
20 |
+
data = pd.read_csv(file_upload)
|
21 |
+
st.write("Uploaded Data Preview:")
|
22 |
+
st.write(data.head())
|
23 |
+
|
24 |
+
if st.button("Submit CSV"):
|
25 |
+
# Predict using the uploaded CSV data
|
26 |
+
predictions = model.predict(data)
|
27 |
+
data['prediction'] = predictions
|
28 |
+
data['prediction'] = data['prediction'].map({1: 'Fraud Transactions', 0: 'Not Fraud Transactions'})
|
29 |
+
|
30 |
+
st.write("Predictions:")
|
31 |
+
st.write(data[['nameOrig', 'nameDest', 'prediction']])
|
32 |
+
|
33 |
+
elif option == "Manual Input":
|
34 |
+
st.write("Manually input data:")
|
35 |
+
# Manual input of data
|
36 |
+
step = st.number_input("Step", min_value=0)
|
37 |
+
type = st.selectbox("Type", ["TRANSFER", "PAYMENT", "DEBIT", "CASH_OUT", "CASH_IN"])
|
38 |
+
amount = st.number_input("Amount", min_value=0.0)
|
39 |
+
nameOrig = st.text_input("Origin Account Name")
|
40 |
+
oldbalanceOrg = st.number_input("Old Balance (Origin)", min_value=0.0)
|
41 |
+
newbalanceOrig = st.number_input("New Balance (Origin)", min_value=0.0)
|
42 |
+
nameDest = st.text_input("Destination Account Name")
|
43 |
+
oldbalanceDest = st.number_input("Old Balance (Destination)", min_value=0.0)
|
44 |
+
newbalanceDest = st.number_input("New Balance (Destination)", min_value=0.0)
|
45 |
+
isFlaggedFraud = st.selectbox("Is Flagged Fraud?", [0, 1])
|
46 |
+
|
47 |
+
if st.button("Submit"):
|
48 |
+
# Create a DataFrame from manual input
|
49 |
+
manual_data = pd.DataFrame({
|
50 |
+
"step": [step],
|
51 |
+
"type": [type],
|
52 |
+
"amount": [amount],
|
53 |
+
"nameOrig": [nameOrig],
|
54 |
+
"oldbalanceOrg": [oldbalanceOrg],
|
55 |
+
"newbalanceOrig": [newbalanceOrig],
|
56 |
+
"nameDest": [nameDest],
|
57 |
+
"oldbalanceDest": [oldbalanceDest],
|
58 |
+
"newbalanceDest": [newbalanceDest],
|
59 |
+
"isFlaggedFraud": [isFlaggedFraud]
|
60 |
+
})
|
61 |
+
|
62 |
+
st.write("Manual Input Data:")
|
63 |
+
st.write(manual_data)
|
64 |
+
|
65 |
+
# Predict using the manually input data
|
66 |
+
manual_predictions = model.predict(manual_data)
|
67 |
+
manual_data['prediction'] = manual_predictions
|
68 |
+
manual_data['prediction'] = manual_data['prediction'].map({1: 'Fraud Transactions', 0: 'Not Fraud Transactions'})
|
69 |
+
|
70 |
+
st.write("Predictions:")
|
71 |
+
st.write(manual_data[['nameOrig', 'nameDest', 'prediction']])
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
app()
|