Spaces:
Sleeping
Sleeping
Download app/models/toxicity_model.py from LeahRocks/SafeSpaceAI: direct link, hf CLI and curl.
- Browser
- Download file 405 Bytes
-
https://huggingface.co/spaces/LeahRocks/SafeSpaceAI/resolve/main/app/models/toxicity_model.py
- Command line
-
hf download hf://spaces/LeahRocks/SafeSpaceAI/app/models/toxicity_model.py
-
curl -L -o toxicity_model.py https://huggingface.co/spaces/LeahRocks/SafeSpaceAI/resolve/main/app/models/toxicity_model.py
405 Bytes
| from transformers import pipeline | |
| # REAL multi-label model | |
| classifier = pipeline( | |
| "text-classification", | |
| model="unitary/unbiased-toxic-roberta", | |
| top_k=None | |
| ) | |
| def predict_toxicity(text: str): | |
| results = classifier(text)[0] | |
| scores = {} | |
| for item in results: | |
| label = item["label"].lower() | |
| score = float(item["score"]) | |
| scores[label] = score | |
| return scores |