Spaces:
Configuration error
Configuration error
Upload agent.py
Browse files
agent.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
# Load fine-tuned translation model
|
4 |
+
translator = pipeline("text-generation", model="JenniferHJF/qwen1.5-emoji-finetuned", max_new_tokens=20, device=0)
|
5 |
+
|
6 |
+
# Load hate speech classifier model
|
7 |
+
classifier = pipeline("text-classification", model="unitary/toxic-bert", top_k=None, device=0)
|
8 |
+
|
9 |
+
def classify_emoji_text(text):
|
10 |
+
translated = translator(f"输入:{text}\n输出:")[0]["generated_text"]
|
11 |
+
translated_text = translated.strip().split("\n")[-1]
|
12 |
+
result = classifier(translated_text)[0]
|
13 |
+
label = result["label"]
|
14 |
+
score = result["score"]
|
15 |
+
return translated_text, label, score
|