File size: 2,311 Bytes
873b63e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import gradio as gr

# 简单的文本处理函数
def process_text(text):
    return f"你输入了: {text}\n字符数: {len(text)}"

# 简单的计算函数
def calculator(a, b, operation):
    if operation == "加法":
        return f"{a} + {b} = {a + b}"
    elif operation == "减法":
        return f"{a} - {b} = {a - b}"
    elif operation == "乘法":
        return f"{a} × {b} = {a * b}"
    elif operation == "除法":
        if b == 0:
            return "错误:除数不能为零"
        return f"{a} ÷ {b} = {a / b:.2f}"

# 创建 Gradio 界面
with gr.Blocks(title="简单演示") as demo:
    gr.Markdown("# 🎯 超级简单的 Gradio 演示")
    
    with gr.Tab("文本处理"):
        with gr.Row():
            with gr.Column():
                text_input = gr.Textbox(label="输入文本", placeholder="在这里输入文字...")
                text_button = gr.Button("处理文本")
            with gr.Column():
                text_output = gr.Textbox(label="处理结果", interactive=False)
    
    with gr.Tab("简单计算器"):
        with gr.Row():
            with gr.Column():
                num1 = gr.Number(label="第一个数字", value=10)
                num2 = gr.Number(label="第二个数字", value=5)
                operation = gr.Radio(
                    choices=["加法", "减法", "乘法", "除法"],
                    label="选择运算",
                    value="加法"
                )
                calc_button = gr.Button("计算")
            with gr.Column():
                calc_output = gr.Textbox(label="计算结果", interactive=False)
    
    with gr.Tab("关于"):
        gr.Markdown("""
        ## 关于这个演示
        
        这是一个超级简单的 Gradio 演示,包含:
        - 📝 文本处理功能
        - 🧮 简单计算器
        - 🎨 美观的界面
        
        不需要任何模型推理!
        """)

    # 连接事件处理
    text_button.click(
        fn=process_text,
        inputs=text_input,
        outputs=text_output
    )
    
    calc_button.click(
        fn=calculator,
        inputs=[num1, num2, operation],
        outputs=calc_output
    )

# 启动应用
if __name__ == "__main__":
    demo.launch(share=True)  # share=True 会生成一个公共链接