Spaces:
Sleeping
Sleeping
File size: 1,366 Bytes
3900591 | 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 | import gradio as gr
import time # Adding a small delay to show the loading state
def reverse_and_count_words(text):
"""
Reverses the input string and counts the number of words.
Added a small delay to simulate processing time.
"""
if not text:
return "", 0
# Simulate some processing time (optional, remove if you want faster response)
time.sleep(1)
reversed_text = text[::-1]
word_count = len(text.split()) # Simple split on whitespace
return reversed_text, word_count
# Create the Gradio interface
# We define inputs and outputs using Gradio components
iface = gr.Interface(
fn=reverse_and_count_words, # The Python function to run
inputs=gr.Textbox(lines=3, placeholder="Enter text here...", label="Your Input Text"), # Input component (a text box)
outputs=[
gr.Textbox(label="Reversed Text"), # Output component (text box for reversed text)
gr.Number(label="Word Count") # Output component (number for word count)
],
title="Simple Text Reverser and Word Counter", # Title for the app
description="Enter any text in the box below. The app will reverse it and tell you how many words it contains." # Description
)
# Launch the Gradio app
# When deployed on Hugging Face Spaces with the Gradio SDK,
# Spaces will automatically run this launch command.
iface.launch() |