Spaces:
Running
Running
Update tools/polite_guard.py
Browse files- tools/polite_guard.py +10 -2
tools/polite_guard.py
CHANGED
@@ -2,9 +2,12 @@ from typing import Any, Optional
|
|
2 |
from smolagents.tools import Tool
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
|
6 |
-
# Classify text into politeness categories
|
7 |
class PoliteGuardTool(Tool):
|
|
|
|
|
|
|
|
|
8 |
name = "polite_guard"
|
9 |
description = "Calls an tool to classifify text by 4 labels from polite to impolite"
|
10 |
inputs = {'input_text': {'type': 'any', 'description': 'Enter text for assessing whether it is respectful'}}
|
@@ -25,6 +28,11 @@ class PoliteGuardTool(Tool):
|
|
25 |
|
26 |
Args:
|
27 |
input_text: The text to classify.
|
|
|
|
|
|
|
|
|
|
|
28 |
"""
|
29 |
try:
|
30 |
classifier = pipeline("text-classification", "Intel/polite-guard")
|
|
|
2 |
from smolagents.tools import Tool
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
|
|
|
6 |
class PoliteGuardTool(Tool):
|
7 |
+
"""Wrapper around a text tool that classifies text into politeness categories.
|
8 |
+
Args:
|
9 |
+
input_text: A string of English text.
|
10 |
+
"""
|
11 |
name = "polite_guard"
|
12 |
description = "Calls an tool to classifify text by 4 labels from polite to impolite"
|
13 |
inputs = {'input_text': {'type': 'any', 'description': 'Enter text for assessing whether it is respectful'}}
|
|
|
28 |
|
29 |
Args:
|
30 |
input_text: The text to classify.
|
31 |
+
|
32 |
+
Returns:
|
33 |
+
dictionary with
|
34 |
+
a. A in result['label'] which is one of the four classifications
|
35 |
+
b. A score in result['score']
|
36 |
"""
|
37 |
try:
|
38 |
classifier = pipeline("text-classification", "Intel/polite-guard")
|