xierui.0097 commited on
Commit
21fc34d
·
1 Parent(s): f0e9666

Add application file

Browse files
Files changed (1) hide show
  1. gradio_app.py +88 -0
gradio_app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import random
4
+
5
+ import gradio as gr
6
+
7
+ from enhance_a_video import VEnhancer
8
+
9
+ examples = [
10
+ ["prompts/astronaut.mp4", "An astronaut flying in space, featuring a steady and smooth perspective", 4, 24, 250],
11
+ ["prompts/cat.mp4", "A cat wearing sunglasses at a pool", 4, 24, 250],
12
+ ["prompts/fish.mp4", "Clown fish swimming through the coral reef", 4, 24, 300],
13
+ ["prompts/iron_man.mp4", "Iron Man flying in the sky", 4, 24, 250],
14
+ ["prompts/raccoon.mp4", "A cute raccoon playing guitar in a boat on the ocean", 4, 24, 250],
15
+ ["prompts/shanghai.mp4", "The bund Shanghai by Hokusai, in the style of Ukiyo", 4, 24, 250],
16
+ ["prompts/gwen.mp4", "Gwen Stacy reading a book, black and white", 4, 24, 250],
17
+ ]
18
+
19
+
20
+ def venhancer_demo(result_dir="./tmp/", version="v1"):
21
+ css = """#input_video {max-width: 1024px !important} #output_vid {max-width: 2048px; max-height:1280px}"""
22
+ venhancer = VEnhancer(result_dir, version=version)
23
+ with gr.Blocks(analytics_enabled=False, css=css) as venhancer_iface:
24
+ gr.Markdown(
25
+ "<div align='center'> <h1> VEnhancer </span> </h1> \
26
+ <a style='font-size:18px;color: #000000' href='https://arxiv.org/abs/2407.07667'> [ArXiv] </a>\
27
+ <a style='font-size:18px;color: #000000' href='https://vchitect.github.io/VEnhancer-project/'> [Project Page] </a> \
28
+ <a style='font-size:18px;color: #000000' href='https://github.com/Vchitect/VEnhancer'> [Github] </a> </div>"
29
+ )
30
+ with gr.Tab(label="VEnhancer"):
31
+ with gr.Column():
32
+ with gr.Row():
33
+ with gr.Column():
34
+ with gr.Row():
35
+ input_video = gr.Video(label="Input Video", elem_id="input_video")
36
+ with gr.Row():
37
+ input_text = gr.Text(label="Prompts")
38
+ with gr.Row():
39
+ up_scale = gr.Slider(
40
+ minimum=1.0, maximum=8.0, step=0.1, label="up scale", value=4, elem_id="up_scale"
41
+ )
42
+ with gr.Row():
43
+ target_fps = gr.Slider(
44
+ minimum=8, maximum=60, step=1, elem_id="target_fps", label="target fps", value=24
45
+ )
46
+ with gr.Row():
47
+ noise_aug = gr.Slider(
48
+ minimum=50, maximum=300, step=1, elem_id="noise_aug", label="noise aug", value=250
49
+ )
50
+ end_btn = gr.Button("Generate")
51
+ with gr.Row():
52
+ output_video = gr.Video(
53
+ label="Generated Video", elem_id="output_vid", autoplay=True, show_share_button=True
54
+ )
55
+
56
+ gr.Examples(
57
+ examples=examples,
58
+ inputs=[input_video, input_text, up_scale, target_fps, noise_aug],
59
+ outputs=[output_video],
60
+ fn=venhancer.enhance_a_video,
61
+ cache_examples=False,
62
+ )
63
+ end_btn.click(
64
+ inputs=[input_video, input_text, up_scale, target_fps, noise_aug],
65
+ outputs=[output_video],
66
+ fn=venhancer.enhance_a_video,
67
+ )
68
+
69
+ return venhancer_iface
70
+
71
+
72
+ def get_parser():
73
+ parser = argparse.ArgumentParser()
74
+ parser.add_argument(
75
+ "--version", type=str, default="v1", choices=["v1", "v2"], help="select the checkpoint version."
76
+ )
77
+
78
+ return parser
79
+
80
+
81
+ if __name__ == "__main__":
82
+ parser = get_parser()
83
+ args = parser.parse_args()
84
+
85
+ result_dir = os.path.join("./", "results")
86
+ venhancer_iface = venhancer_demo(result_dir, args.version)
87
+ venhancer_iface.queue(max_size=12)
88
+ venhancer_iface.launch(max_threads=1)