cjell
commited on
Commit
·
7e3cc26
1
Parent(s):
9fd1a56
nsfw and spam fix
Browse files- app.py +7 -1
- test.nsfw.py +13 -0
- test_spam.py +1 -1
app.py
CHANGED
|
@@ -6,12 +6,13 @@ import os
|
|
| 6 |
|
| 7 |
os.environ["HF_HOME"] = "/tmp"
|
| 8 |
|
| 9 |
-
spam = pipeline("text-classification", model="
|
| 10 |
|
| 11 |
toxic = pipeline("text-classification", model="s-nlp/roberta_toxicity_classifier")
|
| 12 |
|
| 13 |
sentiment = pipeline("text-classification", model = "nlptown/bert-base-multilingual-uncased-sentiment")
|
| 14 |
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
app = FastAPI()
|
|
@@ -36,4 +37,9 @@ def predict_toxic(query: Query):
|
|
| 36 |
@app.post("/sentiment")
|
| 37 |
def predict_sentiment(query: Query):
|
| 38 |
result = sentiment(query.text)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
return {"label": result["label"], "score": result["score"]}
|
|
|
|
| 6 |
|
| 7 |
os.environ["HF_HOME"] = "/tmp"
|
| 8 |
|
| 9 |
+
spam = pipeline("text-classification", model="valurank/distilroberta-spam-comments-detection")
|
| 10 |
|
| 11 |
toxic = pipeline("text-classification", model="s-nlp/roberta_toxicity_classifier")
|
| 12 |
|
| 13 |
sentiment = pipeline("text-classification", model = "nlptown/bert-base-multilingual-uncased-sentiment")
|
| 14 |
|
| 15 |
+
nsfw = pipeline("text-classification", model = "michellejieli/NSFW_text_classifier")
|
| 16 |
|
| 17 |
|
| 18 |
app = FastAPI()
|
|
|
|
| 37 |
@app.post("/sentiment")
|
| 38 |
def predict_sentiment(query: Query):
|
| 39 |
result = sentiment(query.text)[0]
|
| 40 |
+
return {"label": result["label"], "score": result["score"]}
|
| 41 |
+
|
| 42 |
+
@app.post("/nsfw")
|
| 43 |
+
def predict_nsfw(query: Query):
|
| 44 |
+
result = nsfw(query.text)[0]
|
| 45 |
return {"label": result["label"], "score": result["score"]}
|
test.nsfw.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
url = "https://cjell-Demo.hf.space/nsfw"
|
| 4 |
+
|
| 5 |
+
payload = {"text": "Hello"}
|
| 6 |
+
|
| 7 |
+
response = requests.post(url, json=payload)
|
| 8 |
+
|
| 9 |
+
print("Status:", response.status_code)
|
| 10 |
+
try:
|
| 11 |
+
print("JSON:", response.json())
|
| 12 |
+
except Exception:
|
| 13 |
+
print("Raw text:", response.text)
|
test_spam.py
CHANGED
|
@@ -2,7 +2,7 @@ import requests
|
|
| 2 |
|
| 3 |
url = "https://cjell-Demo.hf.space/spam"
|
| 4 |
|
| 5 |
-
payload = {"text": "
|
| 6 |
|
| 7 |
response = requests.post(url, json=payload)
|
| 8 |
|
|
|
|
| 2 |
|
| 3 |
url = "https://cjell-Demo.hf.space/spam"
|
| 4 |
|
| 5 |
+
payload = {"text": "We are having a neighborhood clean up tomorrow if you want to join us."}
|
| 6 |
|
| 7 |
response = requests.post(url, json=payload)
|
| 8 |
|