alihmaou commited on
Commit
6bc0eea
·
verified ·
1 Parent(s): 36b7565

Upload tools/strawberry.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. tools/strawberry.py +10 -6
tools/strawberry.py CHANGED
@@ -5,17 +5,21 @@ import numpy as np
5
 
6
  # --- User Defined Logic ---
7
  def strawberry(word: str, letter: str) -> int:
8
- """Compte le nombre d'occurrences d'une lettre dans un mot.
9
 
10
  Args:
11
- word: Le mot dans lequel compter les occurrences.
12
- letter: La lettre (chaîne de longueur 1) à compter.
13
 
14
  Returns:
15
- Le nombre de fois que la lettre apparaît dans le mot.
16
  """
 
 
 
 
17
  if len(letter) != 1:
18
- raise ValueError("Le paramètre 'letter' doit être une seule lettre.")
19
  return word.count(letter)
20
 
21
  # --- Interface Factory ---
@@ -23,7 +27,7 @@ def create_interface():
23
  return gr.Interface(
24
  fn=strawberry,
25
  inputs=[gr.Textbox(label=k) for k in ['word', 'letter']],
26
- outputs=gr.Textbox(label="Nombre d'occurrences de la lettre"),
27
  title="strawberry",
28
  description="Auto-generated tool: strawberry"
29
  )
 
5
 
6
  # --- User Defined Logic ---
7
  def strawberry(word: str, letter: str) -> int:
8
+ """Count how many times a specific letter appears in a word.
9
 
10
  Args:
11
+ word: The word in which to count occurrences.
12
+ letter: The single letter to count within the word.
13
 
14
  Returns:
15
+ The number of times the specified letter appears in the word.
16
  """
17
+ if not isinstance(word, str):
18
+ raise TypeError("word must be a string")
19
+ if not isinstance(letter, str):
20
+ raise TypeError("letter must be a string")
21
  if len(letter) != 1:
22
+ raise ValueError("letter must be a single character")
23
  return word.count(letter)
24
 
25
  # --- Interface Factory ---
 
27
  return gr.Interface(
28
  fn=strawberry,
29
  inputs=[gr.Textbox(label=k) for k in ['word', 'letter']],
30
+ outputs=gr.Textbox(label="Number of occurrences of the letter in the word"),
31
  title="strawberry",
32
  description="Auto-generated tool: strawberry"
33
  )