cjell commited on
Commit
8b6ec58
·
1 Parent(s): 08c7878

better health check

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -46,30 +46,30 @@ def predict_nsfw(query: Query):
46
 
47
  @app.get("/health")
48
  def health_check():
49
- status = {"server": "running"}
50
-
51
- try:
52
- spam("test")
53
- status["spam"] = "running"
54
- except Exception as e:
55
- status["spam"] = f"error: {str(e)}"
56
-
57
- try:
58
- toxic("test")
59
- status["toxic"] = "running"
60
- except Exception as e:
61
- status["toxic"] = f"error: {str(e)}"
62
-
63
- try:
64
- sentiment("test")
65
- status["sentiment"] = "running"
66
- except Exception as e:
67
- status["sentiment"] = f"error: {str(e)}"
68
-
69
- try:
70
- nsfw("test")
71
- status["nsfw"] = "running"
72
- except Exception as e:
73
- status["nsfw"] = f"error: {str(e)}"
74
 
75
  return status
 
46
 
47
  @app.get("/health")
48
  def health_check():
49
+
50
+ status = {
51
+ "server": "running",
52
+ "models": {}
53
+ }
54
+
55
+ models = {
56
+ "spam": ("valurank/distilroberta-spam-comments-detection", spam),
57
+ "toxic": ("s-nlp/roberta_toxicity_classifier", toxic),
58
+ "sentiment": ("nlptown/bert-base-multilingual-uncased-sentiment", sentiment),
59
+ "nsfw": ("michellejieli/NSFW_text_classifier", nsfw),
60
+ }
61
+
62
+ for key, (model_name, model_pipeline) in models.items():
63
+ try:
64
+ model_pipeline("test")
65
+ status["models"][key] = {
66
+ "model_name": model_name,
67
+ "status": "running"
68
+ }
69
+ except Exception as e:
70
+ status["models"][key] = {
71
+ "model_name": model_name,
72
+ "status": f"error: {str(e)}"
73
+ }
74
 
75
  return status