Spaces:
Runtime error
Runtime error
add inference func
Browse files
app.py
CHANGED
|
@@ -9,6 +9,19 @@ auth_token = os.environ.get("TOKEN_FROM_SECRET")
|
|
| 9 |
model = DistilBertForSequenceClassification.from_pretrained(MODEL_PATH, use_auth_token=auth_token)
|
| 10 |
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
demo = gr.Interface(
|
| 13 |
fn=clf_result,
|
| 14 |
title="Test High Risk Words model v2",
|
|
|
|
| 9 |
model = DistilBertForSequenceClassification.from_pretrained(MODEL_PATH, use_auth_token=auth_token)
|
| 10 |
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased")
|
| 11 |
|
| 12 |
+
clf = pipeline("text-classification", model=model.to("cpu"), tokenizer=tokenizer)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def clf_result(text_input: str) -> str:
|
| 16 |
+
|
| 17 |
+
model_res = clf(text_input)[0]
|
| 18 |
+
label_map = {"LABEL_0": "NOT RISKY", "LABEL_1": "RISKY"}
|
| 19 |
+
label_res = label_map.get(model_res["label"])
|
| 20 |
+
score = model_res["score"]
|
| 21 |
+
res = f"Result: {label_res}\n\nScore: {score}"
|
| 22 |
+
return res
|
| 23 |
+
|
| 24 |
+
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=clf_result,
|
| 27 |
title="Test High Risk Words model v2",
|