| import gradio as gr |
| from PIL import Image |
| import numpy as np |
|
|
| def process_data(text, radio, checkbox, slider, file, image, video, audio, dataframe): |
| return ( |
| text, |
| radio, |
| checkbox, |
| slider, |
| file.name if file else "No file uploaded", |
| image, |
| video, |
| audio, |
| dataframe |
| ) |
| with gr.Blocks() as demo: |
| gr.Markdown('# Gradio 组件示例') |
|
|
| with gr.Row(): |
| text_input = gr.Textbox(label="文本输入") |
| radio_input = gr.Radio(["选项1", "选项2", "选项3"], label="单选按钮") |
| checkbox_input = gr.CheckboxGroup(["选项A", "选项B", "选项C"], label="复选框") |
| slider_input = gr.Slider(minimum=0, maximum=100, label="滑块") |
| |
| with gr.Row(): |
| file_input = gr.File(label="文件上传") |
| image_input = gr.Image(label="图像上传") |
| video_input = gr.Video(label="视频上传") |
| audio_input = gr.Audio(label="音频上传") |
| |
| with gr.Row(): |
| dataframe_input = gr.Dataframe(label="数据表格") |
| |
| submit_button = gr.Button("提交") |
|
|
| with gr.Row(): |
| text_output = gr.Textbox(label="文本输出") |
| radio_output = gr.Textbox(label="单选按钮输出") |
| checkbox_output = gr.Textbox(label="单选按钮输出") |
| slider_output = gr.Textbox(label="单选按钮输出") |
| file_output = gr.Textbox(label="文件输出") |
| image_output = gr.Textbox(label="图像输出") |
| video_output = gr.Textbox(label="视频输出") |
| audio_output = gr.Textbox(label="音频输出") |
| dataframe_output = gr.Textbox(label="数据表格输出") |
| |
| submit_button.click( |
| fn=process_data, |
| inputs=[text_input, radio_input, checkbox_input, slider_input, file_input, image_input, video_input, |
| audio_input, dataframe_input], |
| outputs=[text_output, radio_output, checkbox_output, slider_output, file_output, image_input, video_input, |
| audio_output, dataframe_output] |
| ) |
|
|
| demo.launch(share=True) |