Ahsen Khaliq commited on
Commit
d61c863
1 Parent(s): 48bfa5f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ model = torch.hub.load("PeterL1n/RobustVideoMatting", "mobilenetv3") # or "resnet50"
4
+
5
+ convert_video = torch.hub.load("PeterL1n/RobustVideoMatting", "converter")
6
+
7
+ def inference(video):
8
+ convert_video(
9
+ model, # The loaded model, can be on any device (cpu or cuda).
10
+ input_source=video, # A video file or an image sequence directory.
11
+ input_resize=None, # [Optional] Resize the input (also the output).
12
+ downsample_ratio=0.25, # [Optional] If None, make downsampled max size be 512px.
13
+ output_type='video', # Choose "video" or "png_sequence"
14
+ output_composition='com.mp4', # File path if video; directory path if png sequence.
15
+ output_alpha="pha.mp4", # [Optional] Output the raw alpha prediction.
16
+ output_foreground="fgr.mp4", # [Optional] Output the raw foreground prediction.
17
+ output_video_mbps=4, # Output video mbps. Not needed for png sequence.
18
+ seq_chunk=12, # Process n frames at once for better parallelism.
19
+ num_workers=1, # Only for image sequence input. Reader threads.
20
+ progress=True # Print conversion progress.
21
+ )
22
+ return 'com.mp4'
23
+
24
+ title = "Anime2Sketch"
25
+ description = "demo for Anime2Sketch. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
26
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2104.05703'>Adversarial Open Domain Adaption for Sketch-to-Photo Synthesis</a> | <a href='https://github.com/Mukosame/Anime2Sketch'>Github Repo</a></p>"
27
+
28
+ gr.Interface(
29
+ inference,
30
+ gr.inputs.Video(label="Input"),
31
+ gr.outputs.Video(label="Output"),
32
+ title=title,
33
+ description=description,
34
+ article=article,
35
+ enable_queue=True
36
+ ).launch(debug=True)