import numpy as np import gradio as gr import cv2 def to_black(image): output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) return output def clear_output(input_widget): input_widget = np.array([]) with gr.Blocks() as demo: gr.Markdown("Transfer image or video files using this demo.") with gr.Tabs(): with gr.TabItem("Transfer Image"): with gr.Row(): image_input = gr.Image() image_output = gr.Image() with gr.Row(): image_button = gr.Button("Transfer") clear_image_button = gr.Button("Clear") with gr.TabItem("Transfer Video"): with gr.Row(): video_input = gr.Video() video_output = gr.Video() with gr.Row(): video_button = gr.Button("Transfer") clear_video_button = gr.Button("Clear") image_button.click(to_black, inputs=image_input, outputs=image_output) video_button.click(to_black, inputs=video_input, outputs=video_output) clear_image_button.click(clear_output, inputs=image_input,outputs=image_output) clear_video_button.click(clear_output, inputs=video_input,outputs=video_output) demo.launch() # 启动接口 #demo.launch(server_name='127.0.0.1',server_port=7788)