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

health check

Browse files
Files changed (4) hide show
  1. app.py +31 -1
  2. test_health.py +7 -0
  3. test_sentiment.py +1 -1
  4. test_toxic.py +1 -1
app.py CHANGED
@@ -42,4 +42,34 @@ def predict_sentiment(query: Query):
42
  @app.post("/nsfw")
43
  def predict_nsfw(query: Query):
44
  result = nsfw(query.text)[0]
45
- return {"label": result["label"], "score": result["score"]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  @app.post("/nsfw")
43
  def predict_nsfw(query: Query):
44
  result = nsfw(query.text)[0]
45
+ return {"label": result["label"], "score": result["score"]}
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
test_health.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ url = "https://cjell-Demo.hf.space"
4
+
5
+ if __name__ == "__main__":
6
+ response = requests.get(f"{url}/health", timeout=10)
7
+ print(response.json())
test_sentiment.py CHANGED
@@ -2,7 +2,7 @@ import requests
2
 
3
  url = "https://cjell-Demo.hf.space/sentiment"
4
 
5
- payload = {"text": "The people working outside are loud"}
6
 
7
  response = requests.post(url, json=payload)
8
 
 
2
 
3
  url = "https://cjell-Demo.hf.space/sentiment"
4
 
5
+ payload = {"text": "I am very upset with the new policy."}
6
 
7
  response = requests.post(url, json=payload)
8
 
test_toxic.py CHANGED
@@ -2,7 +2,7 @@ import requests
2
 
3
  url = "https://cjell-Demo.hf.space/toxic"
4
 
5
- payload = {"text": "I do not agree with the policies being put in place by our city council."}
6
 
7
  response = requests.post(url, json=payload)
8
 
 
2
 
3
  url = "https://cjell-Demo.hf.space/toxic"
4
 
5
+ payload = {"text": "I hate you!"}
6
 
7
  response = requests.post(url, json=payload)
8