Spaces:
Configuration error
Configuration error
Upload tool
Browse files- requirements.txt +1 -1
- tool.py +18 -17
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
smolagents
|
2 |
pronouncing
|
|
|
|
|
|
1 |
pronouncing
|
2 |
+
smolagents
|
tool.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
from smolagents.tools import Tool
|
2 |
-
import
|
3 |
import difflib
|
4 |
import string
|
5 |
-
import
|
6 |
|
7 |
class ParodyWordSuggestionTool(Tool):
|
8 |
name = "parody_word_suggester"
|
@@ -10,32 +10,28 @@ class ParodyWordSuggestionTool(Tool):
|
|
10 |
Returns similar-sounding words that rhyme, especially focusing on common vowel sounds."""
|
11 |
inputs = {'target': {'type': 'string', 'description': 'The word you want to find rhyming 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}}
|
12 |
output_type = "string"
|
|
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
{'AY', 'EY'}, # 'bite', 'bait'
|
22 |
-
{'OW', 'AO'}, # 'boat', 'bought'
|
23 |
-
{'AW', 'AO'}, # 'bout', 'bought'
|
24 |
-
{'OY', 'OW'}, # 'boy', 'bow'
|
25 |
-
{'ER', 'AXR'}, # 'bird', 'hurt'
|
26 |
-
]
|
27 |
|
28 |
|
29 |
def _get_last_syllable(self, phones: list) -> tuple:
|
30 |
"""Extract the last syllable (vowel + remaining consonants)."""
|
31 |
last_vowel_idx = -1
|
32 |
last_vowel = None
|
|
|
33 |
|
34 |
# Find the last vowel
|
35 |
for i, phone in enumerate(phones):
|
36 |
# Strip stress markers for checking
|
37 |
base_phone = phone.rstrip('012')
|
38 |
-
for group in
|
39 |
if base_phone in group:
|
40 |
last_vowel_idx = i
|
41 |
last_vowel = base_phone
|
@@ -58,7 +54,8 @@ class ParodyWordSuggestionTool(Tool):
|
|
58 |
if v1 == v2:
|
59 |
return True
|
60 |
|
61 |
-
|
|
|
62 |
if v1 in group and v2 in group:
|
63 |
return True
|
64 |
return False
|
@@ -161,3 +158,7 @@ class ParodyWordSuggestionTool(Tool):
|
|
161 |
|
162 |
return json.dumps(result, indent=2)
|
163 |
|
|
|
|
|
|
|
|
|
|
1 |
from smolagents.tools import Tool
|
2 |
+
import pronouncing
|
3 |
import difflib
|
4 |
import string
|
5 |
+
import json
|
6 |
|
7 |
class ParodyWordSuggestionTool(Tool):
|
8 |
name = "parody_word_suggester"
|
|
|
10 |
Returns similar-sounding words that rhyme, especially focusing on common vowel sounds."""
|
11 |
inputs = {'target': {'type': 'string', 'description': 'The word you want to find rhyming 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}}
|
12 |
output_type = "string"
|
13 |
+
VOWEL_REF = "AH,UH,AX|AE,EH|IY,IH|AO,AA|UW,UH|AY,EY|OW,AO|AW,AO|OY,OW|ER,AXR"
|
14 |
|
15 |
+
def _get_vowel_groups(self):
|
16 |
+
"""Convert the simple string format to usable groups."""
|
17 |
+
groups = []
|
18 |
+
group_strs = self.VOWEL_REF.split("|")
|
19 |
+
for group_str in group_strs:
|
20 |
+
groups.append(group_str.split(","))
|
21 |
+
return groups
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
def _get_last_syllable(self, phones: list) -> tuple:
|
25 |
"""Extract the last syllable (vowel + remaining consonants)."""
|
26 |
last_vowel_idx = -1
|
27 |
last_vowel = None
|
28 |
+
vowel_groups = self._get_vowel_groups()
|
29 |
|
30 |
# Find the last vowel
|
31 |
for i, phone in enumerate(phones):
|
32 |
# Strip stress markers for checking
|
33 |
base_phone = phone.rstrip('012')
|
34 |
+
for group in vowel_groups:
|
35 |
if base_phone in group:
|
36 |
last_vowel_idx = i
|
37 |
last_vowel = base_phone
|
|
|
54 |
if v1 == v2:
|
55 |
return True
|
56 |
|
57 |
+
vowel_groups = self._get_vowel_groups()
|
58 |
+
for group in vowel_groups:
|
59 |
if v1 in group and v2 in group:
|
60 |
return True
|
61 |
return False
|
|
|
158 |
|
159 |
return json.dumps(result, indent=2)
|
160 |
|
161 |
+
|
162 |
+
def __init__(self, *args, **kwargs):
|
163 |
+
self.is_initialized = False
|
164 |
+
|