Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def process_data(text, radio, checkbox, slider, file, image, video, audio, dataframe):
|
| 6 |
+
return (
|
| 7 |
+
text,
|
| 8 |
+
radio,
|
| 9 |
+
checkbox,
|
| 10 |
+
slider,
|
| 11 |
+
file.name if file else "No file uploaded",
|
| 12 |
+
image,
|
| 13 |
+
video,
|
| 14 |
+
audio,
|
| 15 |
+
dataframe
|
| 16 |
+
)
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown('# Gradio 组件示例')
|
| 19 |
+
|
| 20 |
+
with gr.Row():
|
| 21 |
+
text_input = gr.Textbox(label="文本输入")
|
| 22 |
+
radio_input = gr.Radio(["选项1", "选项2", "选项3"], label="单选按钮")
|
| 23 |
+
checkbox_input = gr.CheckboxGroup(["选项A", "选项B", "选项C"], label="复选框")
|
| 24 |
+
slider_input = gr.Slider(minimum=0, maximum=100, label="滑块")
|
| 25 |
+
|
| 26 |
+
with gr.Row():
|
| 27 |
+
file_input = gr.File(label="文件上传")
|
| 28 |
+
image_input = gr.Image(label="图像上传")
|
| 29 |
+
video_input = gr.Video(label="视频上传")
|
| 30 |
+
audio_input = gr.Audio(label="音频上传")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
dataframe_input = gr.Dataframe(label="数据表格")
|
| 34 |
+
|
| 35 |
+
submit_button = gr.Button("提交")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
text_output = gr.Textbox(label="文本输出")
|
| 39 |
+
radio_output = gr.Textbox(label="单选按钮输出")
|
| 40 |
+
checkbox_output = gr.Textbox(label="单选按钮输出")
|
| 41 |
+
slider_output = gr.Textbox(label="单选按钮输出")
|
| 42 |
+
file_output = gr.Textbox(label="文件输出")
|
| 43 |
+
image_output = gr.Textbox(label="图像输出")
|
| 44 |
+
video_output = gr.Textbox(label="视频输出")
|
| 45 |
+
audio_output = gr.Textbox(label="音频输出")
|
| 46 |
+
dataframe_output = gr.Textbox(label="数据表格输出")
|
| 47 |
+
|
| 48 |
+
submit_button.click(
|
| 49 |
+
fn=process_data,
|
| 50 |
+
inputs=[text_input, radio_input, checkbox_input, slider_input, file_input, image_input, video_input,
|
| 51 |
+
audio_input, dataframe_input],
|
| 52 |
+
outputs=[text_output, radio_output, checkbox_output, slider_output, file_output, image_input, video_input,
|
| 53 |
+
audio_output, dataframe_output]
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
demo.launch(share=True)
|