ankitt6174 commited on
Commit
bf5177f
·
1 Parent(s): e62e46b

Hope this is final commit

Browse files
Files changed (4) hide show
  1. .gitignore +1 -3
  2. Dockerfile +20 -0
  3. app.py +111 -0
  4. requirements.txt +0 -0
.gitignore CHANGED
@@ -1,3 +1 @@
1
- venv
2
- app.py
3
- Dockerfile
 
1
+ venv
 
 
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python base image
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements file into the container
8
+ COPY requirements.txt .
9
+
10
+ # Install the dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy the rest of the application files
14
+ COPY . .
15
+
16
+ # Expose the port that Uvicorn will run on
17
+ EXPOSE 7860
18
+
19
+ # Command to run the application
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ import joblib
5
+ import pickle
6
+
7
+ app = FastAPI()
8
+
9
+ def load_model():
10
+ try:
11
+ model = joblib.load("model.joblib")
12
+ print("Model Load Successfully")
13
+ return model
14
+ except Exception as e:
15
+ print(f"Error loading model: {e}")
16
+ model = None
17
+ return model
18
+
19
+ def load_scaler():
20
+ try:
21
+ with open("scaler.pkl", 'rb') as file:
22
+ scaler = pickle.load(file)
23
+ print("Scaler loaded successfully")
24
+ return scaler
25
+ except:
26
+ return ("Error while loading scaler")
27
+
28
+ def load_encoder():
29
+ try:
30
+ with open("encoder.pkl", 'rb') as file:
31
+ encoder = pickle.load(file)
32
+ print("Encoder loaded successfully")
33
+ return encoder
34
+ except:
35
+ print("Error while loading encoder")
36
+
37
+ model = load_model()
38
+ encoder = load_encoder()
39
+ scaler = load_scaler()
40
+
41
+ def load_data(data):
42
+ gender = 1 if data.Gender == 'Male' else 0
43
+ age = data.Age
44
+
45
+ neighbourhood = encoder.transform([data.Neighbourhood])[0]
46
+
47
+ scholarship = 1 if data.Scholarship == 'Yes' else 0
48
+ hipertension = 1 if data.Hipertension == 'Yes' else 0
49
+ diabetes = 1 if data.Diabetes == 'Yes' else 0
50
+ alcoholism = 1 if data.Alcoholism == 'Yes' else 0
51
+ handcap = 1 if data.Handcap == 'Yes' else 0
52
+ smsreceived = 1 if data.SMSreceived == "Yes" else 0
53
+ waitingtime = data.WaitingTime
54
+ appointmentDayWeek = data.AppointmentDayOfWeek
55
+
56
+ lst = ['SameDay', 'Short', 'Mid', 'Long', 'VeryLong']
57
+ waitingGroup = lst.index(data.WaitingGroup)
58
+
59
+ cronic_count = hipertension + diabetes + alcoholism
60
+ chronicGroup = 0
61
+ if cronic_count >= -1 or cronic_count < 0:
62
+ chronicGroup = 0
63
+ elif cronic_count == 0 or cronic_count <= 1:
64
+ chronicGroup = 1
65
+ elif cronic_count > 1 or cronic_count <=3:
66
+ chronicGroup = 2
67
+
68
+ return np.array([gender,
69
+ age,
70
+ neighbourhood,
71
+ scholarship,
72
+ hipertension,
73
+ diabetes,
74
+ alcoholism,
75
+ handcap,
76
+ smsreceived,
77
+ waitingtime,
78
+ appointmentDayWeek,
79
+ waitingGroup,
80
+ chronicGroup])
81
+
82
+ class InputData(BaseModel):
83
+ Gender: str
84
+ Age: int
85
+ Neighbourhood: str
86
+ Scholarship: str
87
+ Hipertension: str
88
+ Diabetes: str
89
+ Alcoholism: str
90
+ Handcap: str
91
+ SMSreceived: str
92
+ WaitingTime: int
93
+ AppointmentDayOfWeek: int
94
+ WaitingGroup: str
95
+
96
+ @app.get("/")
97
+ def home():
98
+ return {"Message": "This is an API for no-show prediction"}
99
+
100
+ @app.post("/predict")
101
+ def prediction(data: InputData):
102
+ print("Data -> ", data)
103
+ print("-"*40)
104
+ raw_data = load_data(data)
105
+ print("Row Data -> ", raw_data)
106
+ print("-"*40)
107
+ scaled_data = scaler.transform(raw_data.reshape(1, -1))
108
+ prediction = model.predict(scaled_data)
109
+
110
+ response = {"message": "Data received successfully!", "prediction": "Patient Will No-Show" if int(prediction[0]) == 1 else "Patient Will Show"}
111
+ return response
requirements.txt ADDED
Binary file (618 Bytes). View file