sibikrish commited on
Commit
4f317ff
Β·
verified Β·
1 Parent(s): d219831

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +234 -236
README.md CHANGED
@@ -1,236 +1,234 @@
1
- ---
2
- title: Creditcard-Fraud-Detection
3
- app_file: gradio_app.py
4
- sdk: gradio
5
- sdk_version: 4.36.1
6
- ---
7
-
8
- <!-- markdownlint-disable -->
9
- <p align="center">
10
- <a href = "https://github.com/Sibikrish3000/Creditcard-Fraud-Detection" > <img src = "https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/blob/main/static/images/creditcard1.jpg?raw=true" alt = "fraud detection image" width=500 height=280> </a>
11
- </p>
12
- <h1 align="center"> Credit Card Fraud Detection Application </h1>
13
-
14
- <p align="center">
15
- This application leverages machine learning to detect fraudulent credit card transactions.
16
- </p>
17
-
18
- <p align="center">
19
- <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Sibikrish3000/Creditcard-Fraud-Detection" alt="GitHub license"></a>
20
- <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/stargazers"><img src="https://img.shields.io/github/stars/Sibikrish3000/Creditcard-Fraud-Detection?style=social" alt="GitHub stars"></a>
21
- <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/issues"><img src="https://img.shields.io/github/issues/Sibikrish3000/Creditcard-Fraud-Detection" alt="GitHub issues"></a>
22
- <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/actions/workflows/quality.yml"><img src="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/actions/workflows/quality.yml/badge.svg" alt="Code Quality"></a>
23
- </p>
24
- <p align="center">
25
- <a href="https://scikit-learn.org/"><img src=https://img.shields.io/badge/sklearn-darkorange.svg?style=flat&logo=scikit-learn&logoColor=white alt="sklearn"></a>
26
- <a href="https://www.python.org"><img src="https://img.shields.io/badge/Python-darkblue.svg?style=flat&logo=python&logoColor=white" alt="language"></a>
27
- <a href="https://fastapi.tiangolo.com/" ><img src="https://img.shields.io/badge/FastAPI-darkgreen.svg?style=flat&logo=fastapi&logoColor=white " alt="fastapi"></a> <a href="https://hub.docker.com/repository/docker/sibikrish3000/creditcard-fraud-detection/"><img src="https://img.shields.io/badge/Docker-blue?style=flat&logo=docker&logoColor=white" alt= "docker"></a>
28
-
29
-
30
-
31
-
32
-
33
- </p>
34
-
35
-
36
- This project contains a Fraud Detection application that includes a FastAPI server for the backend and a Gradio interface for the frontend. The application can predict if a transaction is fraudulent using either XGBoost or RandomForest models.
37
-
38
- [Dataset](https://www.kaggle.com/datasets/kartik2112/fraud-detection)
39
- ## Overview
40
-
41
- 1. **FastAPI Backend**: Handles prediction requests using machine learning models.
42
- 2. **Gradio Frontend**: Provides a user-friendly web interface for users to input transaction details and get predictions.
43
-
44
-
45
- ## Project Structure
46
-
47
- ```
48
-
49
- /Creditcard-Fraud-Detection
50
- β”‚
51
- β”œβ”€β”€/model
52
- β”‚ β”œβ”€β”€ xgboost.pkl
53
- β”‚ └── randomforest.pkl
54
- β”œβ”€β”€/Encoder
55
- β”‚ └── WOEEncoder.pkl
56
- β”‚
57
- β”œβ”€β”€/static
58
- β”‚ └──/images
59
- β”‚ β”œβ”€β”€ github.svg
60
- β”‚ └── api.png
61
- β”‚
62
- β”œβ”€β”€ app.py
63
- β”œβ”€β”€ gradio_app.py
64
- β”œβ”€β”€ docker_app.py
65
- β”œβ”€β”€ Dockerfile
66
- β”œβ”€β”€ docker-compose.yml
67
- β”œβ”€β”€ requirements.txt
68
- β”œβ”€β”€ features.py
69
-
70
- ````
71
-
72
- - `app.py`: Defines the FastAPI application.
73
- - `gradio_app.py`: Defines the Gradio interface.
74
- - `docker_app.py`: Gradio interface for docker
75
- - `Dockerfile`: Dockerfile for building the Docker image.
76
- - `docker-compose.yml`: Docker Compose file for orchestrating the services.
77
- - `requirements.txt`: List of dependencies.
78
- - `features.py`: List of features.
79
- - `model/`: Directory containing pre-trained machine learning models.
80
- - `Encoder/`: Directory containing encoders used for data preprocessing.
81
- - `static/`: Directory containing static files such as images used in the interface.
82
-
83
- ## Getting Started
84
-
85
- ### Prerequisites
86
-
87
- - Docker
88
- - Docker Compose
89
-
90
- ### Installation
91
-
92
- **Clone the repository:**
93
-
94
- ```bash
95
- git clone https://github.com/Sibikrish3000/Creditcard-Fraud-Detection.git
96
- cd Creditcard-Fraud-Detection
97
- ```
98
- ```
99
- git install lfs
100
- git lfs ls-files
101
- ```
102
- ```
103
- git lfs pull
104
- ```
105
-
106
-
107
- ## Running Locally
108
-
109
- ### Using Docker Compose
110
-
111
- 1. Build and start the containers:
112
- ```sh
113
- docker network create AIservice
114
- ```
115
- ```sh
116
- docker-compose up --build
117
- ```
118
-
119
- 2. Access the Gradio interface at [http://localhost:7860](http://localhost:7860).
120
-
121
- ### Using Docker image
122
-
123
- ```sh
124
- docker network create AIservice
125
- ```
126
- ```sh
127
- docker pull sibikrish/creditcard-fraud-detection:latest
128
- docker run sibikrish/creditcard-fraud-detection:latest #or
129
- docker run -d -p 7860:7860 sibikrish/creditcard-fraud-detection:latest
130
- ```
131
-
132
- ### Manually
133
-
134
- To run the application locally without Docker, ensure you have Python installed and follow these steps:
135
-
136
- 1. **Install the dependencies:**
137
-
138
- ```bash
139
- pip install -r requirements.txt
140
- ```
141
-
142
- 2. **Run the FastAPI server:**
143
-
144
- ```bash
145
- uvicorn app:app --host 0.0.0.0 --port 8000
146
- ```
147
-
148
- 3. **Run the Gradio interface:**
149
-
150
- ```bash
151
- python gradio_app.py
152
- ```
153
-
154
- ## Development
155
- ### Running in a Gitpod Cloud Environment
156
-
157
- **Click the button below to start a new development environment:**
158
-
159
- [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Sibikrish3000/Creditcard-Fraud-Detection)
160
- ## Deployment
161
-
162
- ### Using Vercel
163
-
164
- 1. Create a `vercel.json` file in the project root:
165
- ```json
166
- {
167
- "version": 2,
168
- "builds": [
169
- { "src": "app.py", "use": "@vercel/python" },
170
- { "src": "gradio_app.py", "use": "@vercel/python" }
171
- ],
172
- "routes": [
173
- { "src": "/api/(.*)", "dest": "app.py" },
174
- { "src": "/(.*)", "dest": "gradio_app.py" }
175
- ]
176
- }
177
- ```
178
-
179
- 2. Deploy using the Vercel CLI:
180
- ```sh
181
- vercel
182
- ```
183
-
184
-
185
-
186
- ## Usage
187
-
188
- 1. **Access the Gradio Interface:**
189
-
190
- Open your web browser and navigate to `http://localhost:7860` to access the Gradio interface.
191
-
192
- - **Inputs**: Users can input transaction details such as credit card frequency, job, age, gender, category, distance, hour, hours difference between transactions, amount, and choose a model.
193
- - **Output**: The application returns a prediction indicating whether the transaction is legitimate or fraudulent.
194
- - **Flag Option**: Users can enable a flag option to provide feedback on incorrect or suspicious predictions.
195
-
196
-
197
- 2. **Access the FastAPI Documentation:**
198
-
199
- Open your web browser and navigate to `http://localhost:8000/docs` to access the FastAPI documentation.
200
-
201
- ### API Endpoints
202
-
203
- - **POST /predict**
204
-
205
- Predict if a transaction is fraudulent.
206
-
207
- **Request:**
208
-
209
- ```json
210
- {
211
- "cc_freq": int,
212
- "cc_freq_class": int,
213
- "job": str,
214
- "age": int,
215
- "gender_M": int,
216
- "category": str,
217
- "distance_km": float,
218
- "hour": str,
219
- "hours_diff_bet_trans": float,
220
- "amt": float
221
- }
222
- ```
223
-
224
- **Response:**
225
-
226
- ```json
227
- {
228
- "prediction": 0 for legitimate, 1 for fraudulent
229
- }
230
- ```
231
-
232
- ## License
233
-
234
- This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
235
-
236
-
 
1
+ ---
2
+ title: Creditcard-Fraud-Detection
3
+ app_file: gradio_app.py
4
+ sdk: gradio
5
+ sdk_version: 4.37.1
6
+ ---
7
+
8
+ <!-- markdownlint-disable -->
9
+ <p align="center">
10
+ <a href = "https://github.com/Sibikrish3000/Creditcard-Fraud-Detection" > <img src = "https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/blob/main/static/images/creditcard1.jpg?raw=true" alt = "fraud detection image" width=500 height=280> </a>
11
+ </p>
12
+ <h1 align="center"> Credit Card Fraud Detection Application </h1>
13
+
14
+ <p align="center">
15
+ This application leverages machine learning to detect fraudulent credit card transactions.
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Sibikrish3000/Creditcard-Fraud-Detection" alt="GitHub license"></a>
20
+ <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/stargazers"><img src="https://img.shields.io/github/stars/Sibikrish3000/Creditcard-Fraud-Detection?style=social" alt="GitHub stars"></a>
21
+ <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/issues"><img src="https://img.shields.io/github/issues/Sibikrish3000/Creditcard-Fraud-Detection" alt="GitHub issues"></a>
22
+ <a href="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/actions/workflows/quality.yml"><img src="https://github.com/Sibikrish3000/Creditcard-Fraud-Detection/actions/workflows/quality.yml/badge.svg" alt="Code Quality"></a>
23
+ </p>
24
+ <p align="center">
25
+ <a href="https://scikit-learn.org/"><img src=https://img.shields.io/badge/sklearn-darkorange.svg?style=flat&logo=scikit-learn&logoColor=white alt="sklearn"></a>
26
+ <a href="https://www.python.org"><img src="https://img.shields.io/badge/Python-darkblue.svg?style=flat&logo=python&logoColor=white" alt="language"></a>
27
+ <a href="https://fastapi.tiangolo.com/" ><img src="https://img.shields.io/badge/FastAPI-darkgreen.svg?style=flat&logo=fastapi&logoColor=white " alt="fastapi"></a> <a href="https://hub.docker.com/repository/docker/sibikrish3000/creditcard-fraud-detection/"><img src="https://img.shields.io/badge/Docker-blue?style=flat&logo=docker&logoColor=white" alt= "docker"></a>
28
+
29
+
30
+
31
+
32
+
33
+ </p>
34
+
35
+
36
+ This project contains a Fraud Detection application that includes a FastAPI server for the backend and a Gradio interface for the frontend. The application can predict if a transaction is fraudulent using either XGBoost or RandomForest models.
37
+
38
+ [Dataset](https://www.kaggle.com/datasets/kartik2112/fraud-detection)
39
+ ## Overview
40
+
41
+ 1. **FastAPI Backend**: Handles prediction requests using machine learning models.
42
+ 2. **Gradio Frontend**: Provides a user-friendly web interface for users to input transaction details and get predictions.
43
+
44
+
45
+ ## Project Structure
46
+
47
+ ```
48
+
49
+ /Creditcard-Fraud-Detection
50
+ β”‚
51
+ β”œβ”€β”€/model
52
+ β”‚ β”œβ”€β”€ xgboost.pkl
53
+ β”‚ └── randomforest.pkl
54
+ β”œβ”€β”€/Encoder
55
+ β”‚ └── WOEEncoder.pkl
56
+ β”‚
57
+ β”œβ”€β”€/static
58
+ β”‚ └──/images
59
+ β”‚ β”œβ”€β”€ github.svg
60
+ β”‚ └── api.png
61
+ β”‚
62
+ β”œβ”€β”€ app.py
63
+ β”œβ”€β”€ gradio_app.py
64
+ β”œβ”€β”€ docker_app.py
65
+ β”œβ”€β”€ Dockerfile
66
+ β”œβ”€β”€ docker-compose.yml
67
+ β”œβ”€β”€ requirements.txt
68
+ β”œβ”€β”€ features.py
69
+
70
+ ````
71
+
72
+ - `app.py`: Defines the FastAPI application.
73
+ - `gradio_app.py`: Defines the Gradio interface.
74
+ - `docker_app.py`: Gradio interface for docker
75
+ - `Dockerfile`: Dockerfile for building the Docker image.
76
+ - `docker-compose.yml`: Docker Compose file for orchestrating the services.
77
+ - `requirements.txt`: List of dependencies.
78
+ - `features.py`: List of features.
79
+ - `model/`: Directory containing pre-trained machine learning models.
80
+ - `Encoder/`: Directory containing encoders used for data preprocessing.
81
+ - `static/`: Directory containing static files such as images used in the interface.
82
+
83
+ ## Getting Started
84
+
85
+ ### Prerequisites
86
+
87
+ - Docker
88
+ - Docker Compose
89
+
90
+ ### Installation
91
+
92
+ **Clone the repository:**
93
+
94
+ ```bash
95
+ git clone https://github.com/Sibikrish3000/Creditcard-Fraud-Detection.git
96
+ cd Creditcard-Fraud-Detection
97
+ ```
98
+ ```
99
+ git install lfs
100
+ git lfs ls-files
101
+ ```
102
+ ```
103
+ git lfs pull
104
+ ```
105
+
106
+
107
+ ## Running Locally
108
+
109
+ ### Using Docker Compose
110
+
111
+ 1. Build and start the containers:
112
+ ```sh
113
+ docker network create AIservice
114
+ ```
115
+ ```sh
116
+ docker-compose up --build
117
+ ```
118
+
119
+ 2. Access the Gradio interface at [http://localhost:7860](http://localhost:7860).
120
+
121
+ ### Using Docker image
122
+
123
+ ```sh
124
+ docker network create AIservice
125
+ ```
126
+ ```sh
127
+ docker pull sibikrish/creditcard-fraud-detection:latest
128
+ docker run sibikrish/creditcard-fraud-detection:latest #or
129
+ docker run -d -p 7860:7860 sibikrish/creditcard-fraud-detection:latest
130
+ ```
131
+
132
+ ### Manually
133
+
134
+ To run the application locally without Docker, ensure you have Python installed and follow these steps:
135
+
136
+ 1. **Install the dependencies:**
137
+
138
+ ```bash
139
+ pip install -r requirements.txt
140
+ ```
141
+
142
+ 2. **Run the FastAPI server:**
143
+
144
+ ```bash
145
+ uvicorn app:app --host 0.0.0.0 --port 8000
146
+ ```
147
+
148
+ 3. **Run the Gradio interface:**
149
+
150
+ ```bash
151
+ python gradio_app.py
152
+ ```
153
+
154
+ ## Development
155
+ ### Running in a Gitpod Cloud Environment
156
+
157
+ **Click the button below to start a new development environment:**
158
+
159
+ [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Sibikrish3000/Creditcard-Fraud-Detection)
160
+ ## Deployment
161
+
162
+ ### Using Vercel
163
+
164
+ 1. Create a `vercel.json` file in the project root:
165
+ ```json
166
+ {
167
+ "version": 2,
168
+ "builds": [
169
+ { "src": "app.py", "use": "@vercel/python" },
170
+ { "src": "gradio_app.py", "use": "@vercel/python" }
171
+ ],
172
+ "routes": [
173
+ { "src": "/api/(.*)", "dest": "app.py" },
174
+ { "src": "/(.*)", "dest": "gradio_app.py" }
175
+ ]
176
+ }
177
+ ```
178
+
179
+ 2. Deploy using the Vercel CLI:
180
+ ```sh
181
+ vercel
182
+ ```
183
+
184
+
185
+
186
+ ## Usage
187
+
188
+ 1. **Access the Gradio Interface:**
189
+
190
+ Open your web browser and navigate to `http://localhost:7860` to access the Gradio interface.
191
+
192
+ - **Inputs**: Users can input transaction details such as credit card frequency, job, age, gender, category, distance, hour, hours difference between transactions, amount, and choose a model.
193
+ - **Output**: The application returns a prediction indicating whether the transaction is legitimate or fraudulent.
194
+ - **Flag Option**: Users can enable a flag option to provide feedback on incorrect or suspicious predictions.
195
+
196
+
197
+ 2. **Access the FastAPI Documentation:**
198
+
199
+ Open your web browser and navigate to `http://localhost:8000/docs` to access the FastAPI documentation.
200
+
201
+ ### API Endpoints
202
+
203
+ - **POST /predict**
204
+
205
+ Predict if a transaction is fraudulent.
206
+
207
+ **Request:**
208
+
209
+ ```json
210
+ {
211
+ "cc_freq": int,
212
+ "cc_freq_class": int,
213
+ "job": str,
214
+ "age": int,
215
+ "gender_M": int,
216
+ "category": str,
217
+ "distance_km": float,
218
+ "hour": str,
219
+ "hours_diff_bet_trans": float,
220
+ "amt": float
221
+ }
222
+ ```
223
+
224
+ **Response:**
225
+
226
+ ```json
227
+ {
228
+ "prediction": 0 for legitimate, 1 for fraudulent
229
+ }
230
+ ```
231
+
232
+ ## License
233
+
234
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.