omaralaa2004 commited on
Commit
3900591
·
verified ·
1 Parent(s): 3616319

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time # Adding a small delay to show the loading state
3
+
4
+ def reverse_and_count_words(text):
5
+ """
6
+ Reverses the input string and counts the number of words.
7
+ Added a small delay to simulate processing time.
8
+ """
9
+ if not text:
10
+ return "", 0
11
+
12
+ # Simulate some processing time (optional, remove if you want faster response)
13
+ time.sleep(1)
14
+
15
+ reversed_text = text[::-1]
16
+ word_count = len(text.split()) # Simple split on whitespace
17
+
18
+ return reversed_text, word_count
19
+
20
+ # Create the Gradio interface
21
+ # We define inputs and outputs using Gradio components
22
+ iface = gr.Interface(
23
+ fn=reverse_and_count_words, # The Python function to run
24
+ inputs=gr.Textbox(lines=3, placeholder="Enter text here...", label="Your Input Text"), # Input component (a text box)
25
+ outputs=[
26
+ gr.Textbox(label="Reversed Text"), # Output component (text box for reversed text)
27
+ gr.Number(label="Word Count") # Output component (number for word count)
28
+ ],
29
+ title="Simple Text Reverser and Word Counter", # Title for the app
30
+ description="Enter any text in the box below. The app will reverse it and tell you how many words it contains." # Description
31
+ )
32
+
33
+ # Launch the Gradio app
34
+ # When deployed on Hugging Face Spaces with the Gradio SDK,
35
+ # Spaces will automatically run this launch command.
36
+ iface.launch()