File size: 1,385 Bytes
b53f5b9 67cd3a1 b53f5b9 67cd3a1 b53f5b9 723fa63 67cd3a1 b53f5b9 9f19b12 67cd3a1 b53f5b9 | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 | import gradio as gr
def string_converter(text):
if not text:
return "", "", "", "", 0, 0
uppercase = text.upper()
lowercase = text.lower()
titlecase = text.title()
reversed_text = text[::-1]
char_count = len(text)
word_count = len(text.split())
return (
uppercase,
lowercase,
titlecase,
reversed_text,
char_count,
word_count
)
with gr.Blocks(title="String Converter App") as app:
gr.Markdown("## 🔤 String Converter Mini App")
gr.Markdown("Enter text and get multiple string transformations instantly.")
input_text = gr.Textbox(
label="Input Text",
placeholder="Type your text here...",
lines=3
)
convert_btn = gr.Button("Convert")
upper_out = gr.Textbox(label="Uppercase")
lower_out = gr.Textbox(label="Lowercase")
title_out = gr.Textbox(label="Title Case")
reverse_out = gr.Textbox(label="Reversed String")
char_count_out = gr.Number(label="Character Count")
word_count_out = gr.Number(label="Word Count")
convert_btn.click(
fn=string_converter,
inputs=input_text,
outputs=[
upper_out,
lower_out,
title_out,
reverse_out,
char_count_out,
word_count_out
]
)
if __name__ == "__main__":
app.launch() |