YANGYYYY commited on
Commit
e0f15a2
1 Parent(s): 78e2e9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -1,18 +1,30 @@
1
  import numpy as np
2
  import gradio as gr
3
  import cv2
4
- from black import to_black
 
 
 
5
 
6
- # def to_black(image, transfer_style):
7
- # if transfer_style == "Hayao":
8
- # output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转换为灰度图像
9
- # return output
10
- # elif transfer_style == "Shinkai":
11
- # return image
12
- # elif transfer_style == "Kon Satoshi":
13
- # return image
14
- # else:
15
- # return image
 
 
 
 
 
 
 
 
 
16
 
17
  def clear_output(input_widget):
18
  input_widget = np.array([])
@@ -37,7 +49,7 @@ with gr.Blocks() as demo:
37
  video_button = gr.Button("Transfer")
38
  clear_video_button = gr.Button("Clear")
39
 
40
- image_button.click(to_black, inputs=[image_input,image_dropdown], outputs=image_output)
41
  video_button.click(to_black, inputs=[video_input,video_dropdown], outputs=video_output)
42
  clear_image_button.click(clear_output, inputs=image_input,outputs=image_output)
43
  clear_video_button.click(clear_output, inputs=video_input,outputs=video_output)
 
1
  import numpy as np
2
  import gradio as gr
3
  import cv2
4
+ import os
5
+ import argparse
6
+ from inference import Predictor
7
+ #from black import to_black
8
 
9
+ def parse_args():
10
+ parser = argparse.ArgumentParser()
11
+ parser.add_argument('--weight', type=str, default='GeneratorV2_train_photo_Paprika_init.pt')
12
+ parser.add_argument('--device', type=str, default='cpu', help='Device, cuda or cpu')
13
+
14
+ return parser.parse_args()
15
+
16
+ def transfer(image, transfer_style):
17
+ if transfer_style == "Hayao":
18
+ #output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转换为灰度图像
19
+ predictor = Predictor(args.weight, args.device)
20
+ anime_img = predictor.transform_image(args.src, save_path)
21
+ return anime_img
22
+ elif transfer_style == "Shinkai":
23
+ return image
24
+ elif transfer_style == "Kon Satoshi":
25
+ return image
26
+ else:
27
+ return image
28
 
29
  def clear_output(input_widget):
30
  input_widget = np.array([])
 
49
  video_button = gr.Button("Transfer")
50
  clear_video_button = gr.Button("Clear")
51
 
52
+ image_button.click(transfer, inputs=[image_input,image_dropdown], outputs=image_output)
53
  video_button.click(to_black, inputs=[video_input,video_dropdown], outputs=video_output)
54
  clear_image_button.click(clear_output, inputs=image_input,outputs=image_output)
55
  clear_video_button.click(clear_output, inputs=video_input,outputs=video_output)