Spaces:
Configuration error
Configuration error
Upload tool
Browse files
tool.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
from smolagents.tools import Tool
|
2 |
-
import string
|
3 |
import pronouncing
|
4 |
import json
|
|
|
5 |
|
6 |
class ParodyWordSuggestionTool(Tool):
|
7 |
name = "parody_word_suggester"
|
8 |
description = """Suggests phonetically similar funny words using CMU dictionary pronunciations.
|
9 |
Returns similar words from a curated list of funny words, along with their similarity scores."""
|
10 |
-
inputs = {'target': {'type': 'string', 'description': 'The word you want to find funny alternatives for'}, '
|
11 |
output_type = "string"
|
12 |
|
13 |
-
def forward(self, target: str,
|
14 |
"""Get phonetically similar funny word suggestions."""
|
15 |
import pronouncing
|
16 |
import string
|
@@ -20,19 +20,9 @@ class ParodyWordSuggestionTool(Tool):
|
|
20 |
min_similarity = float(min_similarity)
|
21 |
suggestions = []
|
22 |
|
23 |
-
# Parse word list
|
24 |
-
|
25 |
-
|
26 |
-
if not isinstance(words, list):
|
27 |
-
return json.dumps({
|
28 |
-
"error": "word_list must be a JSON string representing a list of words",
|
29 |
-
"suggestions": []
|
30 |
-
}, indent=2)
|
31 |
-
except json.JSONDecodeError:
|
32 |
-
return json.dumps({
|
33 |
-
"error": "Invalid JSON string for word_list",
|
34 |
-
"suggestions": []
|
35 |
-
}, indent=2)
|
36 |
|
37 |
# Get target pronunciation
|
38 |
target_phones = pronouncing.phones_for_word(target)
|
|
|
1 |
from smolagents.tools import Tool
|
|
|
2 |
import pronouncing
|
3 |
import json
|
4 |
+
import string
|
5 |
|
6 |
class ParodyWordSuggestionTool(Tool):
|
7 |
name = "parody_word_suggester"
|
8 |
description = """Suggests phonetically similar funny words using CMU dictionary pronunciations.
|
9 |
Returns similar words from a curated list of funny words, along with their similarity scores."""
|
10 |
+
inputs = {'target': {'type': 'string', 'description': 'The word you want to find funny alternatives for'}, 'word_list_str': {'type': 'string', 'description': 'Comma-separated list of words to check for similarity'}, 'min_similarity': {'type': 'string', 'description': 'Minimum similarity threshold (0.0-1.0)', 'nullable': True}}
|
11 |
output_type = "string"
|
12 |
|
13 |
+
def forward(self, target: str, word_list_str: str, min_similarity: str = "0.7") -> str:
|
14 |
"""Get phonetically similar funny word suggestions."""
|
15 |
import pronouncing
|
16 |
import string
|
|
|
20 |
min_similarity = float(min_similarity)
|
21 |
suggestions = []
|
22 |
|
23 |
+
# Parse comma-separated word list
|
24 |
+
word = ""
|
25 |
+
words = [word.strip() for word in word_list_str.split(',')]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Get target pronunciation
|
28 |
target_phones = pronouncing.phones_for_word(target)
|