runaksh commited on
Commit
0dad85c
·
1 Parent(s): 111900b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -51
app.py CHANGED
@@ -1,32 +1,12 @@
1
- from fastapi import FastAPI, Request, Response
2
-
3
  import gradio
4
  import joblib
5
  from xgboost import XGBClassifier
6
  import pandas as pd
7
  import numpy as np
8
 
9
- from sklearn.metrics import f1_score, precision_score, recall_score
10
- import prometheus_client as prom
11
-
12
- app = FastAPI()
13
-
14
- username = "runaksh"
15
- repo_name = "Patientsurvival-model"
16
- repo_path = username+ '/' + repo_name
17
- xgb_model_loaded = joblib.load("xgboost-model.pkl")
18
-
19
- import pandas as pd
20
-
21
- test_data = pd.read_csv("test_data.csv")
22
-
23
- f1_metric = prom.Gauge('sentiment_f1_score', 'F1 score for random 100 test samples')
24
- precision_metric = prom.Gauge('sentiment_precision_score', 'Precision score for random 100 test samples')
25
- recall_metric = prom.Gauge('sentiment_recall_score', 'Recall score for random 100 test samples')
26
-
27
-
28
- # Function for response generation
29
  # Load your trained model
 
30
 
31
  def bol_to_int(bol):
32
  if bol==True:
@@ -51,27 +31,6 @@ def predict_death_event(feature1, feature2, feature3,feature4, feature5, feature
51
  y_pred = xgb_model_loaded.predict(df)[0]
52
  return y_pred
53
 
54
- # Function for updating metrics
55
- def update_metrics():
56
- global test_data
57
- test = test_data.sample(50)
58
- test_text = test['Text'].values
59
- test_pred = sentiment_model(list(test_text))
60
- pred_labels = [int(pred['label'].split("_")[1]) for pred in test_pred]
61
- f1 = f1_score(test['labels'], pred_labels).round(3)
62
- precision = precision_score(test['labels'], pred_labels).round(3)
63
- recall = recall_score(test['labels'], pred_labels).round(3)
64
-
65
- f1_metric.set(f1)
66
- precision_metric.set(precision)
67
- recall_metric.set(recall)
68
-
69
-
70
- @app.get("/metrics")
71
- async def get_metrics():
72
- update_metrics()
73
- return Response(media_type="text/plain", content= prom.generate_latest())
74
-
75
  # Gradio interface to generate UI link
76
  title = "Patient Survival Prediction"
77
  description = "Predict survival of patient with heart failure, given their clinical record"
@@ -94,11 +53,5 @@ iface = gradio.Interface(fn = predict_death_event,
94
  title = title,
95
  description = description)
96
 
97
- app = gradio.mount_gradio_app(app, iface, path="/")
98
-
99
- #iface.launch(server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface
100
-
101
- if __name__ == "__main__":
102
- # Use this for debugging purposes only
103
- import uvicorn
104
- uvicorn.run(app, host="0.0.0.0", port=8001)
 
1
+ # Import the libraries
 
2
  import gradio
3
  import joblib
4
  from xgboost import XGBClassifier
5
  import pandas as pd
6
  import numpy as np
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Load your trained model
9
+ xgb_model_loaded = joblib.load("xgboost-model.pkl")
10
 
11
  def bol_to_int(bol):
12
  if bol==True:
 
31
  y_pred = xgb_model_loaded.predict(df)[0]
32
  return y_pred
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Gradio interface to generate UI link
35
  title = "Patient Survival Prediction"
36
  description = "Predict survival of patient with heart failure, given their clinical record"
 
53
  title = title,
54
  description = description)
55
 
56
+ #iface.launch(debug=True)
57
+ iface.launch(server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface