File size: 1,063 Bytes
2e04129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

def greet(user_name):
    if not user_name:
        return "Please enter your name"
    return f"Hello {user_name}! πŸ‘‹"

def analyze_text(text):
    if not text:
        return "No text provided"
    words = len(text.split())
    chars = len(text)
    return f"Words: {words}, Characters: {chars}"

with gr.Blocks(title="cli-test-space") as demo:
    gr.Markdown("# cli-test-space\n\nπŸš€ A Hugging Face Space!")
    
    with gr.Tab("πŸ‘‹ Greeting"):
        name_input = gr.Textbox(label="Enter your name")
        greet_btn = gr.Button("Say Hello")
        greet_output = gr.Textbox(label="Greeting")
        greet_btn.click(greet, inputs=name_input, outputs=greet_output)
    
    with gr.Tab("πŸ“ Text Analysis"):
        text_input = gr.Textbox(label="Enter text", lines=3)
        analyze_btn = gr.Button("Analyze")
        text_output = gr.Textbox(label="Analysis")
        analyze_btn.click(analyze_text, inputs=text_input, outputs=text_output)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)