Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,17 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def classify(text):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 2 |
+
import torch
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
model_dir = "saved_model"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_dir)
|
| 8 |
|
| 9 |
def classify(text):
|
| 10 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 11 |
+
outputs = model(**inputs)
|
| 12 |
+
probs = torch.softmax(outputs.logits, dim=1)
|
| 13 |
+
labels = ["non-toxic", "toxic"] # Adjust if needed
|
| 14 |
+
return {labels[i]: float(probs[0][i]) for i in range(len(labels))}
|
| 15 |
+
|
| 16 |
+
gr.Interface(fn=classify, inputs="text", outputs="label").launch()
|
| 17 |
+
|