LazyBoss commited on
Commit
ca726f5
·
verified ·
1 Parent(s): 47a06e4

Upload 6 files

Browse files
Files changed (4) hide show
  1. Dockerfile +16 -0
  2. frauddetection.pkl +3 -0
  3. main.py +57 -0
  4. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ LABEL authors="LazyBoss"
3
+ FROM python:3.11-slim
4
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
5
+ # you will also find guides on how best to write your Dockerfile
6
+
7
+
8
+ WORKDIR /code
9
+
10
+ COPY ./requirements.txt /code/requirements.txt
11
+
12
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
13
+
14
+ COPY . .
15
+
16
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
frauddetection.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87b0d6c6d39201ca68ce8d21257bbbe60c869667d81071b09e41257e38abab5e
3
+ size 2161056
main.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ from pydantic import BaseModel
3
+ from fastapi import FastAPI
4
+ import uvicorn
5
+ import logging
6
+
7
+ logging.basicConfig(level = logging.INFO)
8
+ # 1. Load the trained model
9
+ model = joblib.load('frauddetection.pkl')
10
+
11
+ # 2. Define the input data schema using Pydantic BaseModel
12
+ class InputData(BaseModel):
13
+ Year:int
14
+ Month:int
15
+ UseChip:int
16
+ Amount:int
17
+ MerchantName:int
18
+ MerchantCity:int
19
+ MerchantState:int
20
+ mcc:int
21
+ # Add the rest of the input features (feature4, feature5, ..., feature12)
22
+
23
+ # 3. Create a FastAPI app
24
+ app = FastAPI()
25
+ @app.get('/')
26
+ def welcome():
27
+ return {"Welcome": "This is the home page of the API"}
28
+
29
+
30
+ # 4. Define the prediction route
31
+ @app.post('/predict/')
32
+ async def predict(data: InputData):
33
+ # Convert the input data to a dictionary
34
+ input_data = data.dict()
35
+
36
+ # Extract the input features from the dictionary
37
+ feature1 = input_data['Year']
38
+ feature2=input_data['Month']
39
+ feature3=input_data['UseChip']
40
+ feature4=input_data['Amount']
41
+ feature5=input_data['MerchantName']
42
+ feature6=input_data['MerchantCity']
43
+ feature7=input_data['MerchantState']
44
+ feature8=input_data['mcc']
45
+ # Extract the rest of the input features (feature4, feature5, ..., feature12)
46
+
47
+ # Perform the prediction using the loaded model
48
+ prediction = model.predict([[feature1, feature2, feature3,feature4,feature5,feature6,feature7,feature8]]) # Replace ... with the rest of the features
49
+
50
+ # Convert the prediction to a string (or any other format you prefer)
51
+ result = "Fraud" if prediction[0] == 1 else "Not a Fraud"
52
+
53
+ return {"prediction": result}
54
+ # 4. Run the API with uvicorn
55
+ # Will run on http://127.0.0.1:8000
56
+ if __name__ == '__main__':
57
+ uvicorn.run(app, port=8080)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorna