cjell
commited on
Commit
·
fff3a21
1
Parent(s):
811bfb8
more models
Browse files- .gitignore +2 -0
- app.py +19 -4
- test_sentiment.py +0 -0
- test.py → test_spam.py +1 -1
- test_toxic.py +13 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/test.py
|
| 2 |
+
/test2.py
|
app.py
CHANGED
|
@@ -6,7 +6,13 @@ import os
|
|
| 6 |
|
| 7 |
os.environ["HF_HOME"] = "/tmp"
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
|
@@ -17,8 +23,17 @@ def root():
|
|
| 17 |
class Query(BaseModel):
|
| 18 |
text: str
|
| 19 |
|
| 20 |
-
@app.post("/
|
| 21 |
-
def
|
| 22 |
-
result =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return {"label": result["label"], "score": result["score"]}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
os.environ["HF_HOME"] = "/tmp"
|
| 8 |
|
| 9 |
+
spam = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
|
| 10 |
+
|
| 11 |
+
toxic = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-toxic")
|
| 12 |
+
|
| 13 |
+
sentiment = pipeline("text-classification", model = "nlptown/bert-base-multilingual-uncased-sentiment")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
|
| 17 |
app = FastAPI()
|
| 18 |
|
|
|
|
| 23 |
class Query(BaseModel):
|
| 24 |
text: str
|
| 25 |
|
| 26 |
+
@app.post("/spam")
|
| 27 |
+
def predict_spam(query: Query):
|
| 28 |
+
result = spam(query.text)[0]
|
| 29 |
+
return {"label": result["label"], "score": result["score"]}
|
| 30 |
+
|
| 31 |
+
@app.post("/toxic")
|
| 32 |
+
def predict_toxic(query: Query):
|
| 33 |
+
result = toxic(query.text)[0]
|
| 34 |
return {"label": result["label"], "score": result["score"]}
|
| 35 |
|
| 36 |
+
@app.post("/sentiment")
|
| 37 |
+
def predict_sentiment(query: Query):
|
| 38 |
+
result = toxic(query.text)[0]
|
| 39 |
+
return {"label": result["label"], "score": result["score"]}
|
test_sentiment.py
ADDED
|
File without changes
|
test.py → test_spam.py
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import requests
|
| 2 |
|
| 3 |
-
url = "https://cjell-Demo.hf.space/
|
| 4 |
|
| 5 |
payload = {"text": "Congragulations you have won $1000"}
|
| 6 |
|
|
|
|
| 1 |
import requests
|
| 2 |
|
| 3 |
+
url = "https://cjell-Demo.hf.space/spam"
|
| 4 |
|
| 5 |
payload = {"text": "Congragulations you have won $1000"}
|
| 6 |
|
test_toxic.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
url = "https://cjell-Demo.hf.space/predict"
|
| 4 |
+
|
| 5 |
+
payload = {"text": "I Hate this I want to do bad things you suck!"}
|
| 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)
|