File size: 1,092 Bytes
1022b16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gradio as gr

def process_text(text):
    """
    Simple function that processes text:
    - Converts to uppercase
    - Counts words
    - Returns both results
    """
    if not text:
        return "Please enter some text!", 0
    
    uppercase_text = text.upper()
    word_count = len(text.split())
    
    return uppercase_text, word_count

# Create the Gradio interface
demo = gr.Interface(
    fn=process_text,
    inputs=[
        gr.Textbox(
            label="Enter your text",
            placeholder="Type something here...",
            lines=3
        )
    ],
    outputs=[
        gr.Textbox(label="Uppercase Text", lines=3),
        gr.Number(label="Word Count")
    ],
    title="πŸ“ Text Processor",
    description="Enter some text and I'll convert it to uppercase and count the words!",
    examples=[
        ["Hello world!"],
        ["Gradio makes machine learning demos easy!"],
        ["This is a sample text with multiple words to demonstrate the word counting feature."]
    ],
    theme=gr.themes.Soft()
)

if __name__ == "__main__":
    demo.launch()