ashwml commited on
Commit
91c5cdb
·
1 Parent(s): fd43fa0

Upload 5 files

Browse files
Files changed (4) hide show
  1. Dockerfile +23 -0
  2. app.py +91 -0
  3. requirements.txt +13 -0
  4. test.csv +99 -0
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # pull python base image
2
+ FROM python:3.10
3
+
4
+ COPY requirements.txt requirements.txt
5
+
6
+ # update pip
7
+ RUN pip install --upgrade pip
8
+
9
+ # install dependencies
10
+ RUN pip install -r requirements.txt
11
+
12
+ RUN useradd -m -u 1000 myuser
13
+
14
+ USER myuser
15
+
16
+ # copy application files
17
+ COPY --chown=myuser . .
18
+
19
+ # expose port for application
20
+ EXPOSE 8001
21
+
22
+ # start fastapi application
23
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import numpy as np
4
+ from fastapi import FastAPI,request,Response
5
+ from sklearn.metrics import accuracy_score, f1_score
6
+ import prometheus_client as prom
7
+ # from transformers import pipeline
8
+
9
+
10
+
11
+ #model
12
+ save_file_name="xgboost-model.pkl"
13
+ loaded_model = pickle.load(open(save_file_name, 'rb'))
14
+
15
+ app=FastAPI()
16
+
17
+ username="ashwml"
18
+ repo_name="prometheus_model"
19
+ model=username+'/'+repo_name
20
+ test_data=pd.read_csv("test.csv")
21
+
22
+
23
+ f1_metric = prom.Gauge('death_f1_score', 'F1 score for test samples')
24
+
25
+ # Function for updating metrics
26
+ def update_metrics():
27
+ test = test_data.sample(100)
28
+ X = test.iloc[:, :-1].values
29
+ y = test['DEATH_EVENT'].values
30
+
31
+ # test_text = test['Text'].values
32
+ test_pred = loaded_model.predict(X)
33
+ #pred_labels = [int(pred['label'].split("_")[1]) for pred in test_pred]
34
+
35
+ f1 = f1_score( y , test_pred).round(3)
36
+
37
+ #f1 = f1_score(test['labels'], pred_labels).round(3)
38
+
39
+ f1_metric.set(f1)
40
+
41
+
42
+
43
+ def predict_death_event(age, anaemia, creatinine_phosphokinase ,diabetes ,ejection_fraction, high_blood_pressure ,platelets ,serum_creatinine, serum_sodium, sex ,smoking ,time):
44
+ input=[[age, anaemia, creatinine_phosphokinase ,diabetes ,ejection_fraction, high_blood_pressure ,platelets ,serum_creatinine, serum_sodium, sex ,smoking ,time]]
45
+ result=loaded_model.predict(input)
46
+
47
+ if result[0]==1:
48
+ return 'Positive'
49
+ else:
50
+ return 'Negative'
51
+ return result
52
+
53
+
54
+ @app.get("/metrics")
55
+ async def get_metrics():
56
+ update_metrics()
57
+ return Response(media_type="text/plain", content= prom.generate_latest())
58
+
59
+
60
+
61
+ title = "Patient Survival Prediction"
62
+ description = "Predict survival of patient with heart failure, given their clinical record"
63
+
64
+ out_response = gr.components.Textbox(type="text", label='Death_event')
65
+
66
+ iface = gr.Interface(fn=predict_death_event,
67
+ inputs=[
68
+ gr.Slider(18, 100, value=20, label="Age"),
69
+ gr.Slider(0, 1, value=1, label="anaemia"),
70
+ gr.Slider(100, 2000, value=20, label="creatinine_phosphokinase"),
71
+ gr.Slider(0, 1, value=1, label="diabetes"),
72
+ gr.Slider(18, 100, value=20, label="ejection_fraction"),
73
+ gr.Slider(0, 1, value=1, label="high_blood_pressure"),
74
+ gr.Slider(18, 400000, value=20, label="platelets"),
75
+ gr.Slider(1, 10, value=20, label="serum_creatinine"),
76
+ gr.Slider(100, 200, value=20, label="serum_sodium"),
77
+ gr.Slider(0, 1, value=1, label="sex"),
78
+ gr.Slider(0, 1, value=1, label="smoking"),
79
+ gr.Slider(1, 10, value=20, label="time"),
80
+ ],
81
+ outputs = [out_response])
82
+
83
+
84
+ app = gradio.mount_gradio_app(app, iface, path="/")
85
+ iface.launch(server_name = "0.0.0.0", server_port = 8001)
86
+
87
+
88
+ if __name__ == "__main__":
89
+ # Use this for debugging purposes only
90
+ import uvicorn
91
+ uvicorn.run(app, host="0.0.0.0", port=8001)
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio
2
+ pickle5
3
+ numpy
4
+ xgboost
5
+
6
+
7
+ uvicorn
8
+ fastapi
9
+ python-multipart
10
+ pydantic
11
+
12
+ scikit-learn
13
+ prometheus-client
test.csv ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ age,anaemia,creatinine_phosphokinase,diabetes,ejection_fraction,high_blood_pressure,platelets,serum_creatinine,serum_sodium,sex,smoking,time,DEATH_EVENT
2
+ 55.0,0,7861,0,38,0,263358.03,1.1,136,1,0,6,1
3
+ 65.0,0,157,0,65,0,263358.03,1.5,138,0,0,10,1
4
+ 80.0,1,123,0,35,1,388000.0,9.4,133,1,1,10,1
5
+ 82.0,1,379,0,50,0,47000.0,1.3,136,1,0,13,1
6
+ 45.0,0,582,0,14,0,166000.0,0.8,127,1,0,14,1
7
+ 65.0,1,128,1,30,1,297000.0,1.6,136,0,0,20,1
8
+ 53.0,0,63,1,60,0,368000.0,0.8,135,1,0,22,0
9
+ 80.0,0,148,1,38,0,149000.0,1.9,144,1,1,23,1
10
+ 95.0,1,112,0,40,1,196000.0,1.0,138,0,0,24,1
11
+ 70.0,0,122,1,45,1,284000.0,1.3,136,1,1,26,1
12
+ 85.0,0,23,0,45,0,360000.0,3.0,132,1,0,28,1
13
+ 70.0,0,582,0,20,1,263358.03,1.83,134,1,1,31,1
14
+ 70.0,0,571,1,45,1,185000.0,1.2,139,1,1,33,1
15
+ 50.0,0,582,1,38,0,310000.0,1.9,135,1,1,35,1
16
+ 51.0,0,1380,0,25,1,271000.0,0.9,130,1,0,38,1
17
+ 60.0,0,582,1,38,1,451000.0,0.6,138,1,1,40,1
18
+ 57.0,1,129,0,30,0,395000.0,1.0,140,0,0,42,1
19
+ 53.0,1,91,0,20,1,418000.0,1.4,139,0,0,43,1
20
+ 60.0,1,260,1,38,0,255000.0,2.2,132,0,1,45,1
21
+ 70.0,1,75,0,35,0,223000.0,2.7,138,1,1,54,0
22
+ 72.0,0,364,1,20,1,254000.0,1.3,136,1,1,59,1
23
+ 45.0,0,7702,1,25,1,390000.0,1.0,139,1,0,60,1
24
+ 50.0,0,318,0,40,1,216000.0,2.3,131,0,0,60,1
25
+ 45.0,0,582,0,80,0,263358.03,1.18,137,0,0,63,0
26
+ 60.0,0,68,0,20,0,119000.0,2.9,127,1,1,64,1
27
+ 85.0,0,5882,0,35,0,243000.0,1.0,132,1,1,72,1
28
+ 69.0,0,582,0,20,0,266000.0,1.2,134,1,1,73,1
29
+ 60.0,1,47,0,20,0,204000.0,0.7,139,1,1,73,1
30
+ 70.0,0,92,0,60,1,317000.0,0.8,140,0,1,74,0
31
+ 70.0,0,66,1,45,0,249000.0,0.8,136,1,1,80,0
32
+ 42.0,0,582,0,60,0,263358.03,1.18,137,0,0,82,0
33
+ 80.0,0,898,0,25,0,149000.0,1.1,144,1,1,87,0
34
+ 55.0,0,748,0,45,0,263000.0,1.3,137,1,0,88,0
35
+ 50.0,0,369,1,25,0,252000.0,1.6,136,1,0,90,0
36
+ 58.0,1,400,0,40,0,164000.0,1.0,139,0,0,91,0
37
+ 60.0,1,96,1,60,1,271000.0,0.7,136,0,0,94,0
38
+ 60.0,0,96,1,38,0,228000.0,0.75,140,0,0,95,0
39
+ 60.0,1,582,0,30,1,127000.0,0.9,145,0,0,95,0
40
+ 43.0,1,358,0,50,0,237000.0,1.3,135,0,0,97,0
41
+ 61.0,0,248,0,30,1,267000.0,0.7,136,1,1,104,0
42
+ 60.0,1,1082,1,45,0,250000.0,6.1,131,1,0,107,0
43
+ 81.0,0,4540,0,35,0,231000.0,1.18,137,1,1,107,0
44
+ 65.0,1,59,1,60,0,172000.0,0.9,137,0,0,107,0
45
+ 68.0,1,646,0,25,0,305000.0,2.1,130,1,0,108,0
46
+ 80.0,0,805,0,38,0,263358.03,1.1,134,1,0,109,1
47
+ 46.0,1,291,0,35,0,348000.0,0.9,140,0,0,109,0
48
+ 61.0,1,84,0,40,1,229000.0,0.9,141,0,0,110,0
49
+ 50.0,0,185,0,30,0,266000.0,0.7,141,1,1,112,0
50
+ 52.0,0,132,0,30,0,218000.0,0.7,136,1,1,112,0
51
+ 72.0,0,233,0,45,1,235000.0,2.5,135,0,0,115,1
52
+ 50.0,0,115,0,45,1,184000.0,0.9,134,1,1,118,0
53
+ 65.0,1,335,0,35,1,235000.0,0.8,136,0,0,120,0
54
+ 52.0,1,58,0,35,0,277000.0,1.4,136,0,0,120,0
55
+ 45.0,1,130,0,35,0,174000.0,0.8,139,1,1,121,0
56
+ 63.0,1,582,0,40,0,448000.0,0.9,137,1,1,123,0
57
+ 45.0,0,2442,1,30,0,334000.0,1.1,139,1,0,129,1
58
+ 65.0,0,582,1,40,0,270000.0,1.0,138,0,0,140,0
59
+ 70.0,0,835,0,35,1,305000.0,0.8,133,0,0,145,0
60
+ 51.0,1,582,1,35,0,263358.03,1.5,136,1,1,145,0
61
+ 60.0,1,95,0,60,0,337000.0,1.0,138,1,1,146,0
62
+ 59.0,1,176,1,25,0,221000.0,1.0,136,1,1,150,1
63
+ 65.0,0,395,1,25,0,265000.0,1.2,136,1,1,154,1
64
+ 60.667,1,104,1,30,0,389000.0,1.5,136,1,0,171,1
65
+ 60.667,1,151,1,40,1,201000.0,1.0,136,0,0,172,0
66
+ 80.0,0,582,1,35,0,350000.0,2.1,134,1,0,174,0
67
+ 50.0,1,121,1,40,0,260000.0,0.7,130,1,0,175,0
68
+ 45.0,0,582,1,38,1,263358.03,1.18,137,0,0,185,0
69
+ 78.0,1,64,0,40,0,277000.0,0.7,137,1,1,187,0
70
+ 40.0,1,101,0,40,0,226000.0,0.8,141,0,0,187,0
71
+ 60.0,1,2281,1,40,0,283000.0,1.0,141,0,0,187,0
72
+ 70.0,0,212,1,17,1,389000.0,1.0,136,1,1,188,0
73
+ 78.0,0,224,0,50,0,481000.0,1.4,138,1,1,192,0
74
+ 68.0,1,1021,1,35,0,271000.0,1.1,134,1,0,197,0
75
+ 73.0,0,582,0,20,0,263358.03,1.83,134,1,0,198,1
76
+ 65.0,0,118,0,50,0,194000.0,1.1,145,1,1,200,0
77
+ 42.0,1,86,0,35,0,365000.0,1.1,139,1,1,201,0
78
+ 75.0,0,675,1,60,0,265000.0,1.4,125,0,0,205,0
79
+ 65.0,0,56,0,25,0,237000.0,5.0,130,0,0,207,0
80
+ 70.0,0,232,0,30,0,173000.0,1.2,132,1,0,210,0
81
+ 40.0,0,90,0,35,0,255000.0,1.1,136,1,1,212,0
82
+ 64.0,0,143,0,25,0,246000.0,2.4,135,1,0,214,0
83
+ 50.0,0,2522,0,30,1,404000.0,0.5,139,0,0,214,0
84
+ 50.0,0,245,0,45,1,274000.0,1.0,133,1,0,215,0
85
+ 52.0,1,191,1,30,1,334000.0,1.0,142,1,1,216,0
86
+ 65.0,0,326,0,38,0,294000.0,1.7,139,0,0,220,0
87
+ 55.0,0,66,0,40,0,203000.0,1.0,138,1,0,233,0
88
+ 62.0,1,655,0,40,0,283000.0,0.7,133,0,0,233,0
89
+ 65.0,1,258,1,25,0,198000.0,1.4,129,1,0,235,1
90
+ 68.0,1,157,1,60,0,208000.0,1.0,140,0,0,237,0
91
+ 50.0,1,298,0,35,0,362000.0,0.9,140,1,1,240,0
92
+ 56.0,1,135,1,38,0,133000.0,1.7,140,1,0,244,0
93
+ 40.0,0,582,1,35,0,222000.0,1.0,132,1,0,244,0
94
+ 70.0,0,618,0,35,0,327000.0,1.1,142,0,0,245,0
95
+ 50.0,1,54,0,40,0,279000.0,0.8,141,1,0,250,0
96
+ 65.0,0,892,1,35,0,263358.03,1.1,142,0,0,256,0
97
+ 90.0,1,337,0,38,0,390000.0,0.9,144,0,0,256,0
98
+ 63.0,1,103,1,35,0,179000.0,0.9,136,1,1,270,0
99
+ 45.0,0,2413,0,38,0,140000.0,1.4,140,1,1,280,0