File size: 1,799 Bytes
1f25689
 
2064e3d
1f25689
e8df8bc
 
 
 
 
 
 
 
 
 
1f25689
838acff
 
 
1f25689
838acff
1f25689
838acff
1f25689
 
 
838acff
e8df8bc
838acff
 
 
 
e8df8bc
838acff
 
 
 
 
 
e8df8bc
 
838acff
 
1f25689
 
 
 
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
import numpy as np
import gradio as gr
import cv2

def to_black(image, transfer_style):
    if transfer_style == "Hayao":
         output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转换为灰度图像
         return output
    elif transfer_style == "Shinkai":
        return image
    elif transfer_style == "Kon Satoshi":
        return image
    else:
        return image

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_dropdown = gr.Dropdown(label="Transfer Style",choices=["Hayao", "Shinkai", "Kon Satoshi"])
                image_button = gr.Button("Transfer")
                clear_image_button = gr.Button("Clear")
        with gr.TabItem("Transfer Video"):
            with gr.Row():
                video_dropdown = gr.Dropdown(label="Transfer Style",choices=["Hayao", "Shinkai", "Kon Satoshi"])
                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,image_dropdown], outputs=image_output)
    video_button.click(to_black, inputs=[video_input,video_dropdown], 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)