utilities / tools /strawberry.py
alihmaou's picture
Upload tools/strawberry.py with huggingface_hub
e7cdb0e verified
import gradio as gr
import json
from PIL import Image
import numpy as np
# --- User Defined Logic ---
def strawberry(word: str, letter: str) -> int:
"""Count how many times a given letter appears in a word.
Args:
word: The word in which to count occurrences.
letter: A single character whose occurrences are to be counted.
Returns:
The number of times the letter appears in the word (case-insensitive).
"""
if not isinstance(word, str):
raise TypeError("word must be a string")
if not isinstance(letter, str) or len(letter) != 1:
raise ValueError("letter must be a single character string")
return word.lower().count(letter.lower())
# --- Interface Factory ---
def create_interface():
return gr.Interface(
fn=strawberry,
inputs=[gr.Textbox(label=k) for k in ['word', 'letter']],
outputs=gr.Textbox(label="Number of occurrences of the letter in the word"),
title="strawberry",
description="Auto-generated tool: strawberry"
)