jbilcke-hf HF staff commited on
Commit
3ed2ed6
1 Parent(s): b105b21

Update base/app.py

Browse files
Files changed (1) hide show
  1. base/app.py +17 -60
base/app.py CHANGED
@@ -16,21 +16,12 @@ from diffusers.schedulers import DDIMScheduler, DDPMScheduler, PNDMScheduler, Eu
16
  from diffusers.models import AutoencoderKL
17
  from transformers import CLIPTokenizer, CLIPTextModel, CLIPTextModelWithProjection
18
 
 
19
 
20
  config_path = "./base/configs/sample.yaml"
21
  args = OmegaConf.load("./base/configs/sample.yaml")
22
  device = "cuda" if torch.cuda.is_available() else "cpu"
23
 
24
- css = """
25
- h1 {
26
- text-align: center;
27
- }
28
- #component-0 {
29
- max-width: 730px;
30
- margin: auto;
31
- }
32
- """
33
-
34
  sd_path = args.pretrained_path
35
  unet = get_models(args, sd_path).to(device, dtype=torch.float16)
36
  state_dict = find_model("./pretrained_models/lavie_base.pt")
@@ -42,7 +33,10 @@ unet.eval()
42
  vae.eval()
43
  text_encoder_one.eval()
44
 
45
- def infer(prompt, seed_inp, ddim_steps,cfg, infer_type):
 
 
 
46
  if seed_inp!=-1:
47
  setup_seed(seed_inp)
48
  else:
@@ -79,38 +73,21 @@ def infer(prompt, seed_inp, ddim_steps,cfg, infer_type):
79
  return args.output_folder + prompt[0:30].replace(' ', '_') + '-'+str(seed_inp)+'-'+str(ddim_steps)+'-'+str(cfg)+ '-.mp4'
80
 
81
 
82
- title = """
83
- <div style="text-align: center; max-width: 700px; margin: 0 auto;">
84
- <div
85
- style="
86
- display: inline-flex;
87
- align-items: center;
88
- gap: 0.8rem;
89
- font-size: 1.75rem;
90
- "
91
- >
92
- <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
93
- Intern路Vchitect (Text-to-Video)
94
- </h1>
95
- </div>
96
- <p style="margin-bottom: 10px; font-size: 94%">
97
- Apply Intern路Vchitect to generate a video
98
- </p>
99
- </div>
100
- """
101
-
102
- with gr.Blocks(css='style.css') as demo:
103
- gr.Markdown("<font color=red size=10><center>LaVie: Text-to-Video generation</center></font>")
104
- gr.Markdown(
105
- """<div style="text-align:center">
106
- [<a href="https://arxiv.org/abs/2309.15103">Arxiv Report</a>] | [<a href="https://vchitect.github.io/LaVie-project/">Project Page</a>] | [<a href="https://github.com/Vchitect/LaVie">Github</a>]</div>
107
- """
108
- )
109
  with gr.Column():
110
  with gr.Row(elem_id="col-container"):
111
  with gr.Column():
112
 
113
- prompt = gr.Textbox(value="a corgi walking in the park at sunrise, oil painting style", label="Prompt", placeholder="enter prompt", show_label=True, elem_id="prompt-in", min_width=200, lines=2)
114
  infer_type = gr.Dropdown(['ddpm','ddim','eulerdiscrete'], label='infer_type',value='ddim')
115
  ddim_steps = gr.Slider(label='Steps', minimum=50, maximum=300, value=50, step=1)
116
  seed_inp = gr.Slider(value=-1,label="seed (for random generation, use -1)",show_label=True,minimum=-1,maximum=2147483647)
@@ -120,29 +97,9 @@ with gr.Blocks(css='style.css') as demo:
120
  submit_btn = gr.Button("Generate video")
121
  video_out = gr.Video(label="Video result", elem_id="video-output")
122
 
123
- inputs = [prompt, seed_inp, ddim_steps, cfg, infer_type]
124
  outputs = [video_out]
125
 
126
- ex = gr.Examples(
127
- examples = [['a corgi walking in the park at sunrise, oil painting style',400,50,7,'ddim'],
128
- ['a cut teddy bear reading a book in the park, oil painting style, high quality',700,50,7,'ddim'],
129
- ['an epic tornado attacking above a glowing city at night, the tornado is made of smoke, highly detailed',230,50,7,'ddim'],
130
- ['a jar filled with fire, 4K video, 3D rendered, well-rendered',400,50,7,'ddim'],
131
- ['a teddy bear walking in the park, oil painting style, high quality',400,50,7,'ddim'],
132
- ['a teddy bear walking on the street, 2k, high quality',100,50,7,'ddim'],
133
- ['a panda taking a selfie, 2k, high quality',400,50,7,'ddim'],
134
- ['a polar bear playing drum kit in NYC Times Square, 4k, high resolution',400,50,7,'ddim'],
135
- ['jungle river at sunset, ultra quality',400,50,7,'ddim'],
136
- ['a shark swimming in clear Carribean ocean, 2k, high quality',400,50,7,'ddim'],
137
- ['A steam train moving on a mountainside by Vincent van Gogh',230,50,7,'ddim'],
138
- ['a confused grizzly bear in calculus class',1000,50,7,'ddim']],
139
- fn = infer,
140
- inputs=[prompt, seed_inp, ddim_steps,cfg,infer_type],
141
- outputs=[video_out],
142
- cache_examples=False,
143
- )
144
- ex.dataset.headers = [""]
145
-
146
  submit_btn.click(infer, inputs, outputs)
147
 
148
  demo.queue(max_size=12).launch()
 
16
  from diffusers.models import AutoencoderKL
17
  from transformers import CLIPTokenizer, CLIPTextModel, CLIPTextModelWithProjection
18
 
19
+ SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
20
 
21
  config_path = "./base/configs/sample.yaml"
22
  args = OmegaConf.load("./base/configs/sample.yaml")
23
  device = "cuda" if torch.cuda.is_available() else "cpu"
24
 
 
 
 
 
 
 
 
 
 
 
25
  sd_path = args.pretrained_path
26
  unet = get_models(args, sd_path).to(device, dtype=torch.float16)
27
  state_dict = find_model("./pretrained_models/lavie_base.pt")
 
33
  vae.eval()
34
  text_encoder_one.eval()
35
 
36
+ def infer(secret_token, prompt, seed_inp, ddim_steps,cfg, infer_type):
37
+ if secret_token != SECRET_TOKEN:
38
+ raise gr.Error(f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
39
+
40
  if seed_inp!=-1:
41
  setup_seed(seed_inp)
42
  else:
 
73
  return args.output_folder + prompt[0:30].replace(' ', '_') + '-'+str(seed_inp)+'-'+str(ddim_steps)+'-'+str(cfg)+ '-.mp4'
74
 
75
 
76
+
77
+ with gr.Blocks() as demo:
78
+ gr.HTML("""
79
+ <div style="z-index: 100; position: fixed; top: 0px; right: 0px; left: 0px; bottom: 0px; width: 100%; height: 100%; background: white; display: flex; align-items: center; justify-content: center; color: black;">
80
+ <div style="text-align: center; color: black;">
81
+ <p style="color: black;">This space is a REST API to programmatically generate MP4 videos.</p>
82
+ <p style="color: black;">Interested in using it? Look no further than the <a href="https://huggingface.co/spaces/Vchitect/LaVie" target="_blank">original space</a>!</p>
83
+ </div>
84
+ </div>""")
85
+ secret_token = gr.Textbox(label="Secret token")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  with gr.Column():
87
  with gr.Row(elem_id="col-container"):
88
  with gr.Column():
89
 
90
+ prompt = gr.Textbox(value="", label="Prompt", placeholder="enter prompt", show_label=True, elem_id="prompt-in", min_width=200, lines=2)
91
  infer_type = gr.Dropdown(['ddpm','ddim','eulerdiscrete'], label='infer_type',value='ddim')
92
  ddim_steps = gr.Slider(label='Steps', minimum=50, maximum=300, value=50, step=1)
93
  seed_inp = gr.Slider(value=-1,label="seed (for random generation, use -1)",show_label=True,minimum=-1,maximum=2147483647)
 
97
  submit_btn = gr.Button("Generate video")
98
  video_out = gr.Video(label="Video result", elem_id="video-output")
99
 
100
+ inputs = [secret_token, prompt, seed_inp, ddim_steps, cfg, infer_type]
101
  outputs = [video_out]
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  submit_btn.click(infer, inputs, outputs)
104
 
105
  demo.queue(max_size=12).launch()