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