Spaces:
Build error
Build error
Upload tools/strawberry.py with huggingface_hub
Browse files- 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 |
-
"""
|
| 9 |
|
| 10 |
Args:
|
| 11 |
-
word:
|
| 12 |
-
letter:
|
| 13 |
|
| 14 |
Returns:
|
| 15 |
-
|
| 16 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
if len(letter) != 1:
|
| 18 |
-
raise ValueError("
|
| 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="
|
| 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 |
)
|