Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +69 -0
- iso_fraude_dection.joblib +3 -0
- requirements.txt +9 -0
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# heading
|
| 6 |
+
html_temp = """
|
| 7 |
+
<div style="background-color:black;padding:10px">
|
| 8 |
+
<h2 style="color:white;text-align:center;">Fraud Detection APP </h2>
|
| 9 |
+
</div>
|
| 10 |
+
"""
|
| 11 |
+
st.markdown(html_temp, unsafe_allow_html=True)
|
| 12 |
+
|
| 13 |
+
# image
|
| 14 |
+
url="https://tse2.mm.bing.net/th?id=OIP.ROc4vnkJBbKTf8uWRQpldAHaDt&pid=Api&P=0&h=180"
|
| 15 |
+
st.image(url, use_container_width=True)
|
| 16 |
+
|
| 17 |
+
@st.cache_data
|
| 18 |
+
def convert_df(df):
|
| 19 |
+
return df.to_csv(index=False).encode("utf-8")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# loading model
|
| 23 |
+
model=joblib.load('iso_fraude_dection.joblib')
|
| 24 |
+
|
| 25 |
+
# Required column in dataframe
|
| 26 |
+
req_col= pd.DataFrame(columns=['step', 'type', 'amount'])
|
| 27 |
+
|
| 28 |
+
# Download the template
|
| 29 |
+
csv = convert_df(req_col)
|
| 30 |
+
st.download_button(
|
| 31 |
+
label="Download Template",
|
| 32 |
+
data=csv,
|
| 33 |
+
file_name="Template.csv",
|
| 34 |
+
mime="text/csv")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# uploading model
|
| 38 |
+
file=st.file_uploader('Please Upload the CSV File', type=["csv"])
|
| 39 |
+
col1, col2 = st.columns(2)
|
| 40 |
+
if file is not None:
|
| 41 |
+
with col1:
|
| 42 |
+
df = pd.read_csv(file,encoding='ISO-8859-1')
|
| 43 |
+
st.write("Uploaded File Preview:")
|
| 44 |
+
st.dataframe(df.head())
|
| 45 |
+
|
| 46 |
+
if st.button("Predict Outliers"):
|
| 47 |
+
try:
|
| 48 |
+
# Ensure required columns exist
|
| 49 |
+
required_columns = req_col
|
| 50 |
+
if not all(col in df.columns for col in required_columns):
|
| 51 |
+
st.error("Uploaded file does not match the required template structure.")
|
| 52 |
+
else:
|
| 53 |
+
predictions = model.predict(df)
|
| 54 |
+
with col2:
|
| 55 |
+
df['Anomaly'] = ['Anomaly' if pred == -1 else 'Not Anomaly' for pred in predictions]
|
| 56 |
+
st.write("Anomaly Detection Results:")
|
| 57 |
+
st.dataframe(df.head())
|
| 58 |
+
result_csv = convert_df(df)
|
| 59 |
+
st.download_button(
|
| 60 |
+
label="Download Results",
|
| 61 |
+
data=result_csv,
|
| 62 |
+
file_name="Anomaly_Detection_Results.csv",
|
| 63 |
+
mime="text/csv")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
except Exception as e:
|
| 67 |
+
st.error(f"An error occurred while processing the file: {e}")
|
| 68 |
+
|
| 69 |
+
|
iso_fraude_dection.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d0b11487de440b38d90b3e1ccffdd906e30f9c83a64e393de8a0c6678c7eb4da
|
| 3 |
+
size 1263000
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
joblib==1.2.0
|
| 2 |
+
matplotlib==3.7.1
|
| 3 |
+
matplotlib-inline==0.1.6
|
| 4 |
+
numpy==1.26.4
|
| 5 |
+
pandas==1.5.3
|
| 6 |
+
scikit-learn==1.6.0
|
| 7 |
+
streamlit==1.41.1
|
| 8 |
+
seaborn==0.12.2
|
| 9 |
+
tabulate==0.8.10
|