YANGYYYY commited on
Commit
7232d95
1 Parent(s): 623c086

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -19,6 +19,17 @@ def parse_args():
19
 
20
  return parser.parse_args()
21
 
 
 
 
 
 
 
 
 
 
 
 
22
  def transfer(image, transfer_style):
23
  if transfer_style == "Hayao":
24
  #output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转换为灰度图像
@@ -42,6 +53,29 @@ def transfer(image, transfer_style):
42
  else:
43
  return image
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def clear_output(input_widget):
46
  input_widget = np.array([])
47
 
@@ -66,7 +100,7 @@ with gr.Blocks() as demo:
66
  clear_video_button = gr.Button("Clear")
67
 
68
  image_button.click(transfer, inputs=[image_input,image_dropdown], outputs=image_output)
69
- video_button.click(transfer, inputs=[video_input,video_dropdown], outputs=video_output)
70
  clear_image_button.click(clear_output, inputs=image_input,outputs=image_output)
71
  clear_video_button.click(clear_output, inputs=video_input,outputs=video_output)
72
  demo.launch()
 
19
 
20
  return parser.parse_args()
21
 
22
+ def parse_args_video():
23
+ parser = argparse.ArgumentParser()
24
+ parser.add_argument('--weight', type=str, default='GeneratorV2_train_photo_Hayao_init.pt')
25
+ #parser.add_argument('--src', type=str, default='dataset/video/花.mp4', help='Path to input video')
26
+ #parser.add_argument('--out', type=str, default='dataset/video_Hayao/hua_hayao.mp4', help='Path to save new video')
27
+ parser.add_argument('--batch-size', type=int, default=4)
28
+ parser.add_argument('--start', type=int, default=0, help='Start time of video (second)')
29
+ parser.add_argument('--end', type=int, default=10, help='End time of video (second), 0 if not set')
30
+
31
+ return parser.parse_args()
32
+
33
  def transfer(image, transfer_style):
34
  if transfer_style == "Hayao":
35
  #output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转换为灰度图像
 
53
  else:
54
  return image
55
 
56
+
57
+ def transfer_video(video, transfer_style):
58
+ if transfer_style == "Hayao":
59
+ #output = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转换为灰度图像
60
+ #os.system("wget https://huggingface.co/YANGYYYY/cartoonize/resolve/main/GeneratorV2_train_photo_Hayao_init.pt")
61
+ args = parse_args_video()
62
+ anime_video = Predictor(args.weight).transform_video(video, args.batch_size, start=args.start, end=args.end)
63
+ return anime_video
64
+ elif transfer_style == "Shinkai":
65
+ args = parse_args()
66
+ args.weight = 'GeneratorV2_train_photo_Shinkai_init.pt'
67
+ predictor = Predictor(args.weight, args.device)
68
+ anime_img = predictor.transform_image(image)
69
+ return anime_img
70
+ elif transfer_style == "Kon Satoshi":
71
+ args = parse_args()
72
+ args.weight = 'GeneratorV2_train_photo_Paprika_init.pt'
73
+ predictor = Predictor(args.weight, args.device)
74
+ anime_img = predictor.transform_image(image)
75
+ return anime_img
76
+ else:
77
+ return image
78
+
79
  def clear_output(input_widget):
80
  input_widget = np.array([])
81
 
 
100
  clear_video_button = gr.Button("Clear")
101
 
102
  image_button.click(transfer, inputs=[image_input,image_dropdown], outputs=image_output)
103
+ video_button.click(transfer_video, inputs=[video_input,video_dropdown], outputs=video_output)
104
  clear_image_button.click(clear_output, inputs=image_input,outputs=image_output)
105
  clear_video_button.click(clear_output, inputs=video_input,outputs=video_output)
106
  demo.launch()