Spaces:
Configuration error
Configuration error
Upload tool
Browse files
tool.py
CHANGED
@@ -7,7 +7,7 @@ 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': '
|
11 |
output_type = "string"
|
12 |
|
13 |
def forward(self, target: str, word_list_str: str, min_similarity: str = "0.7") -> str:
|
@@ -20,9 +20,19 @@ class ParodyWordSuggestionTool(Tool):
|
|
20 |
min_similarity = float(min_similarity)
|
21 |
suggestions = []
|
22 |
|
23 |
-
# Parse
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# Get target pronunciation
|
28 |
target_phones = pronouncing.phones_for_word(target)
|
|
|
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': 'JSON string of word list (e.g. \'["word1", "word2"]\')'}, '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:
|
|
|
20 |
min_similarity = float(min_similarity)
|
21 |
suggestions = []
|
22 |
|
23 |
+
# Parse JSON string to list
|
24 |
+
try:
|
25 |
+
words = json.loads(word_list_str)
|
26 |
+
if not isinstance(words, list):
|
27 |
+
return json.dumps({
|
28 |
+
"error": "word_list_str must be a JSON string representing a list",
|
29 |
+
"suggestions": []
|
30 |
+
}, indent=2)
|
31 |
+
except json.JSONDecodeError:
|
32 |
+
return json.dumps({
|
33 |
+
"error": "Invalid JSON string for word_list_str",
|
34 |
+
"suggestions": []
|
35 |
+
}, indent=2)
|
36 |
|
37 |
# Get target pronunciation
|
38 |
target_phones = pronouncing.phones_for_word(target)
|