Haoxin Chen commited on
Commit
1e5bda6
1 Parent(s): 58ef683
Files changed (3) hide show
  1. app.py +71 -95
  2. demo_test.py +16 -0
  3. requirements.txt +1 -0
app.py CHANGED
@@ -1,116 +1,92 @@
1
  import os
2
  import sys
3
- import time
4
  import gradio as gr
5
- from videocrafter_test import Text2Video
6
  sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def videocrafter_demo(result_dir='./tmp/'):
9
  text2video = Text2Video(result_dir)
 
10
  with gr.Blocks(analytics_enabled=False) as videocrafter_iface:
11
  gr.Markdown("<div align='center'> <h2> VideoCrafter: A Toolkit for Text-to-Video Generation and Editing </span> </h2> \
12
  <a style='font-size:18px;color: #efefef' href='https://github.com/VideoCrafter/VideoCrafter'> Github </div>")
13
- with gr.Row().style(equal_height=False):
14
- with gr.Tab(label="VideoCrafter"):
15
- input_text = gr.Text(label='Prompts')
16
- model_choices=['origin','vangogh','frozen','yourname', 'coco']
17
-
18
- with gr.Row():
19
- model_index = gr.Dropdown(label='Models', elem_id=f"model", choices=model_choices, value=model_choices[0], type="index",interactive=True)
20
-
21
- with gr.Row():
22
- steps = gr.Slider(minimum=1, maximum=200, step=1, elem_id=f"steps", label="Sampling steps", value=50)
23
- eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="eta")
24
-
25
- with gr.Row():
26
- lora_scale = gr.Slider(minimum=0.0, maximum=2.0, step=0.1, label='Lora Scale', value=1.0, elem_id="lora_scale")
27
- cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='CFG Scale', value=15.0, elem_id="cfg_scale")
28
-
29
- send_btn = gr.Button("Send")
30
-
31
  with gr.Column():
32
- output_video_1 = gr.PlayableVideo()
33
-
34
- with gr.Row():
35
- examples = [
36
- [
37
- 'an elephant is walking under the sea, 4K, high definition',
38
- 50,
39
- 'origin',
40
- 1,
41
- 15,
42
- 1,
43
- ],
44
- [
45
- 'an astronaut riding a horse in outer space',
46
- 25,
47
- 'origin',
48
- 1,
49
- 15,
50
- 1,
51
- ],
52
- [
53
- 'a monkey is playing a piano',
54
- 25,
55
- 'vangogh',
56
- 1,
57
- 15,
58
- 1,
59
- ],
60
- [
61
- 'A fire is burning on a candle',
62
- 25,
63
- 'frozen',
64
- 1,
65
- 15,
66
- 1,
67
- ],
68
- [
69
- 'a horse is drinking in the river',
70
- 25,
71
- 'yourname',
72
- 1,
73
- 15,
74
- 1,
75
- ],
76
- [
77
- 'Robot dancing in times square',
78
- 25,
79
- 'coco',
80
- 1,
81
- 15,
82
- 1,
83
- ],
84
-
85
- ]
86
- gr.Examples(examples=examples,
87
- inputs=[
88
- input_text,
89
- steps,
90
- model_index,
91
- eta,
92
- cfg_scale,
93
- lora_scale],
94
- outputs=[output_video_1],
95
- fn=text2video.get_prompt,
96
- cache_examples=False)
97
  #cache_examples=os.getenv('SYSTEM') == 'spaces')
98
-
99
  send_btn.click(
100
  fn=text2video.get_prompt,
101
- inputs=[
102
- input_text,
103
- steps,
104
- model_index,
105
- eta,
106
- cfg_scale,
107
- lora_scale,
108
- ],
109
  outputs=[output_video_1],
110
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  return videocrafter_iface
112
 
113
  if __name__ == "__main__":
114
  result_dir = os.path.join('./', 'results')
115
  videocrafter_iface = videocrafter_demo(result_dir)
116
- videocrafter_iface.launch()
 
1
  import os
2
  import sys
 
3
  import gradio as gr
4
+ from demo_test import Text2Video, VideoContorl
5
  sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
6
 
7
+ t2v_examples = [
8
+ ['an elephant is walking under the sea, 4K, high definition',50,'origin',1,15,1,],
9
+ ['an astronaut riding a horse in outer space',25,'origin',1,15,1,],
10
+ ['a monkey is playing a piano',25,'vangogh',1,15,1,],
11
+ ['A fire is burning on a candle',25,'frozen',1,15,1,],
12
+ ['a horse is drinking in the river',25,'yourname',1,15,1,],
13
+ ['Robot dancing in times square',25,'coco',1,15,1,],
14
+ ]
15
+
16
+ control_examples = [
17
+ ['01.mp4', 'a dog', 0, 50, 15, 1]
18
+ ]
19
+
20
  def videocrafter_demo(result_dir='./tmp/'):
21
  text2video = Text2Video(result_dir)
22
+ videocontrol = VideoContorl()
23
  with gr.Blocks(analytics_enabled=False) as videocrafter_iface:
24
  gr.Markdown("<div align='center'> <h2> VideoCrafter: A Toolkit for Text-to-Video Generation and Editing </span> </h2> \
25
  <a style='font-size:18px;color: #efefef' href='https://github.com/VideoCrafter/VideoCrafter'> Github </div>")
26
+ #######t2v#######
27
+ with gr.Tab(label="Text2Video"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  with gr.Column():
29
+ with gr.Row().style(equal_height=False):
30
+ with gr.Column():
31
+ input_text = gr.Text(label='Prompts')
32
+ model_choices=['origin','vangogh','frozen','yourname', 'coco']
33
+ with gr.Row():
34
+ model_index = gr.Dropdown(label='Models', elem_id=f"model", choices=model_choices, value=model_choices[0], type="index",interactive=True)
35
+ with gr.Row():
36
+ steps = gr.Slider(minimum=1, maximum=200, step=1, elem_id=f"steps", label="Sampling steps", value=50)
37
+ eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="eta")
38
+ with gr.Row():
39
+ lora_scale = gr.Slider(minimum=0.0, maximum=2.0, step=0.1, label='Lora Scale', value=1.0, elem_id="lora_scale")
40
+ cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='CFG Scale', value=15.0, elem_id="cfg_scale")
41
+ send_btn = gr.Button("Send")
42
+ with gr.Tab(label='show'):
43
+ output_video_1 = gr.Video().style(width=384)
44
+ gr.Examples(examples=t2v_examples,
45
+ inputs=[input_text,steps,model_index,eta,cfg_scale,lora_scale],
46
+ outputs=[output_video_1],
47
+ fn=text2video.get_prompt,
48
+ cache_examples=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  #cache_examples=os.getenv('SYSTEM') == 'spaces')
 
50
  send_btn.click(
51
  fn=text2video.get_prompt,
52
+ inputs=[input_text,steps,model_index,eta,cfg_scale,lora_scale,],
 
 
 
 
 
 
 
53
  outputs=[output_video_1],
54
  )
55
+ #######videocontrol######
56
+ with gr.Tab(label='VideoControl'):
57
+ with gr.Column():
58
+ with gr.Row():
59
+ # with gr.Tab(label='input'):
60
+ with gr.Column():
61
+ vc_input_video = gr.Video().style(width=256)
62
+ with gr.Row():
63
+ vc_input_text = gr.Text(label='Prompts')
64
+ with gr.Row():
65
+ vc_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="vc_eta")
66
+ vc_cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.5, label='CFG Scale', value=15.0, elem_id="vc_cfg_scale")
67
+ with gr.Row():
68
+ vc_steps = gr.Slider(minimum=1, maximum=200, step=1, elem_id="vc_steps", label="Sampling steps", value=50)
69
+ frame_stride = gr.Slider(minimum=0 , maximum=8, step=1, label='Frame Stride', value=0, elem_id="vc_frame_stride")
70
+
71
+ vc_end_btn = gr.Button("Send")
72
+ with gr.Tab(label='Result'):
73
+ vc_output_info = gr.Text(label='Info')
74
+ vc_output_video = gr.Video().style(width=384)
75
+
76
+ gr.Examples(examples=control_examples,
77
+ inputs=[vc_input_video, vc_input_text, frame_stride, vc_steps, vc_cfg_scale, vc_eta],
78
+ outputs=[vc_output_info, vc_output_video],
79
+ fn = videocontrol.get_video,
80
+ cache_examples=False
81
+ )
82
+ vc_end_btn.click(inputs=[vc_input_video, vc_input_text, frame_stride, vc_steps, vc_cfg_scale, vc_eta],
83
+ outputs=[vc_output_info, vc_output_video],
84
+ fn = videocontrol.get_video
85
+ )
86
+
87
  return videocrafter_iface
88
 
89
  if __name__ == "__main__":
90
  result_dir = os.path.join('./', 'results')
91
  videocrafter_iface = videocrafter_demo(result_dir)
92
+ videocrafter_iface.launch(server_name='0.0.0.0', server_port=80)
demo_test.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class Text2Video():
2
+ def __init__(self, result_dir='./tmp/') -> None:
3
+ pass
4
+
5
+ def get_prompt(self, input_text, steps=50, model_index=0, eta=1.0, cfg_scale=15.0, lora_scale=1.0):
6
+
7
+ return '01.mp4'
8
+
9
+ class VideoContorl:
10
+ def __init__(self) -> None:
11
+ pass
12
+
13
+ def get_video(self, input_video, input_prompt, frame_stride, vc_steps, vc_cfg_scale, vc_eta):
14
+
15
+ return 'su','01.mp4'
16
+
requirements.txt CHANGED
@@ -17,4 +17,5 @@ moviepy
17
  av
18
  xformers
19
  gradio
 
20
  # -e .
 
17
  av
18
  xformers
19
  gradio
20
+ timm
21
  # -e .