Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
moderate_pipe = pipeline("text-classification", model="KoalaAI/Text-Moderation")
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
return {r["label"]: r["score"] for r in results}
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
| 6 |
moderate_pipe = pipeline("text-classification", model="KoalaAI/Text-Moderation")
|
| 7 |
|
| 8 |
+
class TextInput(BaseModel):
|
| 9 |
+
text: str
|
|
|
|
| 10 |
|
| 11 |
+
@app.post("/moderate")
|
| 12 |
+
async def moderate_text(input: TextInput):
|
| 13 |
+
results = moderate_pipe(input.text)
|
| 14 |
+
return {r["label"]: r["score"] for r in results}
|