patruff commited on
Commit
e53cc7e
·
verified ·
1 Parent(s): 5e82e43

Upload tool

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -1
  2. tool.py +8 -13
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- pronouncing
2
  smolagents
 
 
 
1
  smolagents
2
+ pronouncing
tool.py CHANGED
@@ -1,7 +1,7 @@
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"
@@ -23,11 +23,6 @@ class ParodyWordSuggestionTool(Tool):
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",
@@ -42,24 +37,24 @@ class ParodyWordSuggestionTool(Tool):
42
  "suggestions": []
43
  }, indent=2)
44
 
45
- target_phones = target_phones[0].split()
46
 
47
  # Check each word
48
  for word in words:
49
  phones = pronouncing.phones_for_word(word)
50
  if phones: # Only process if word is in dictionary
51
- phones = phones[0].split()
52
 
53
- # Calculate similarity using overlap
54
- overlap = len(set(phones) & set(target_phones))
55
- total = min(len(phones), len(target_phones))
56
  similarity = overlap / total if total > 0 else 0.0
57
 
58
  if similarity >= min_similarity:
59
  suggestions.append({
60
  "word": word,
61
  "similarity": round(similarity, 3),
62
- "syllables": pronouncing.syllable_count(phones)
63
  })
64
 
65
  # Sort by similarity score descending
 
1
  from smolagents.tools import Tool
 
 
2
  import string
3
+ import json
4
+ import pronouncing
5
 
6
  class ParodyWordSuggestionTool(Tool):
7
  name = "parody_word_suggester"
 
23
  # Parse JSON string to list
24
  try:
25
  words = json.loads(word_list_str)
 
 
 
 
 
26
  except json.JSONDecodeError:
27
  return json.dumps({
28
  "error": "Invalid JSON string for word_list_str",
 
37
  "suggestions": []
38
  }, indent=2)
39
 
40
+ target_phones = target_phones[0] # Change: Don't split here
41
 
42
  # Check each word
43
  for word in words:
44
  phones = pronouncing.phones_for_word(word)
45
  if phones: # Only process if word is in dictionary
46
+ phones = phones[0] # Change: Don't split this either
47
 
48
+ # Calculate similarity using overlap (modifying to work with full phone strings)
49
+ overlap = len(set(phones.split()) & set(target_phones.split()))
50
+ total = min(len(phones.split()), len(target_phones.split()))
51
  similarity = overlap / total if total > 0 else 0.0
52
 
53
  if similarity >= min_similarity:
54
  suggestions.append({
55
  "word": word,
56
  "similarity": round(similarity, 3),
57
+ "syllables": pronouncing.syllable_count(phones) # This should work now as phones is a string
58
  })
59
 
60
  # Sort by similarity score descending