Spaces:
Running
Running
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() | |