Andres commited on
Commit
e2bc4fb
·
verified ·
1 Parent(s): 4b9e887

Create app.py

Browse files

Count the number of occurrences of a letter in a word or text

Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def letter_counter(word: str, letter: str) -> int:
4
+ """
5
+ Count the number of occurrences of a letter in a word or text.
6
+ Args:
7
+ word (str): The input text to search through
8
+ letter (str): The letter to search for
9
+ Returns:
10
+ int: The number of times the letter appears in the text
11
+ """
12
+ word = word.lower()
13
+ letter = letter.lower()
14
+ count = word.count(letter)
15
+ return count
16
+
17
+ # Create a standard Gradio interface
18
+ demo = gr.Interface(
19
+ fn=letter_counter,
20
+ inputs=["textbox", "textbox"],
21
+ outputs="number",
22
+ title="Letter Counter",
23
+ description="Enter text and a letter to count how many times the letter appears in the text."
24
+ )
25
+
26
+ if __name__ == "__main__":
27
+ demo.launch()