Step-Audio-R1 / demo.py
moevis's picture
Create demo.py
873b63e verified
raw
history blame
2.31 kB
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 会生成一个公共链接