frankleeeee commited on
Commit
f58f053
1 Parent(s): 8a77797
Files changed (1) hide show
  1. app.py +53 -44
app.py CHANGED
@@ -52,7 +52,7 @@ def install_dependencies(enable_optimization=False):
52
  )
53
 
54
  if enable_optimization:
55
- # install ape
56
  if not _is_package_available("apex"):
57
  subprocess.run(
58
  f'{sys.executable} -m pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" git+https://github.com/NVIDIA/apex.git',
@@ -142,6 +142,10 @@ def parse_args():
142
  # ============================
143
  # Main Gradio Script
144
  # ============================
 
 
 
 
145
  # read config
146
  args = parse_args()
147
  config = read_config(CONFIG_MAP[args.model_type])
@@ -177,54 +181,59 @@ def run_inference(prompt_text):
177
  saved_path = save_sample(samples[0], fps=config.fps, save_path=filename)
178
  return saved_path
179
 
180
- # create demo
181
- with gr.Blocks() as demo:
182
- with gr.Row():
183
- with gr.Column():
184
- gr.HTML(
185
- """
186
- <div style='text-align: center;'>
187
- <p align="center">
188
- <img src="https://github.com/hpcaitech/Open-Sora/raw/main/assets/readme/icon.png" width="250"/>
189
- </p>
190
- <div style="display: flex; gap: 10px; justify-content: center;">
191
- <a href="https://github.com/hpcaitech/Open-Sora/stargazers"><img src="https://img.shields.io/github/stars/hpcaitech/Open-Sora?style=social"></a>
192
- <a href="https://hpcaitech.github.io/Open-Sora/"><img src="https://img.shields.io/badge/Gallery-View-orange?logo=&amp"></a>
193
- <a href="https://discord.gg/kZakZzrSUT"><img src="https://img.shields.io/badge/Discord-join-blueviolet?logo=discord&amp"></a>
194
- <a href="https://join.slack.com/t/colossalaiworkspace/shared_invite/zt-247ipg9fk-KRRYmUl~u2ll2637WRURVA"><img src="https://img.shields.io/badge/Slack-ColossalAI-blueviolet?logo=slack&amp"></a>
195
- <a href="https://twitter.com/yangyou1991/status/1769411544083996787?s=61&t=jT0Dsx2d-MS5vS9rNM5e5g"><img src="https://img.shields.io/badge/Twitter-Discuss-blue?logo=twitter&amp"></a>
196
- <a href="https://raw.githubusercontent.com/hpcaitech/public_assets/main/colossalai/img/WeChat.png"><img src="https://img.shields.io/badge/微信-小助手加群-green?logo=wechat&amp"></a>
197
- <a href="https://hpc-ai.com/blog/open-sora-v1.0"><img src="https://img.shields.io/badge/Open_Sora-Blog-blue"></a>
 
 
 
198
  </div>
199
- <h1 style='margin-top: 5px;'>Open-Sora: Democratizing Efficient Video Production for All</h1>
200
- </div>
201
- """
202
- )
203
 
204
- with gr.Row():
205
- with gr.Column():
206
- prompt_text = gr.Textbox(show_label=False, placeholder="Describe your video here", lines=4)
207
- submit_button = gr.Button("Generate video")
208
 
209
- with gr.Column():
210
- output_video = gr.Video()
211
 
212
- submit_button.click(fn=run_inference, inputs=[prompt_text], outputs=output_video)
213
 
214
- gr.Examples(
215
- examples=[
216
- [
217
- "The video captures the majestic beauty of a waterfall cascading down a cliff into a serene lake. The waterfall, with its powerful flow, is the central focus of the video. The surrounding landscape is lush and green, with trees and foliage adding to the natural beauty of the scene. The camera angle provides a bird's eye view of the waterfall, allowing viewers to appreciate the full height and grandeur of the waterfall. The video is a stunning representation of nature's power and beauty.",
 
218
  ],
219
- ],
220
- fn=run_inference,
221
- inputs=[
222
- prompt_text,
223
- ],
224
- outputs=[output_video],
225
- cache_examples=True,
226
- )
 
 
 
227
 
228
- # launch
229
- demo.launch(server_port=args.port, server_name=args.host, share=args.share)
230
 
 
52
  )
53
 
54
  if enable_optimization:
55
+ # install apex for fused layernorm
56
  if not _is_package_available("apex"):
57
  subprocess.run(
58
  f'{sys.executable} -m pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" git+https://github.com/NVIDIA/apex.git',
 
142
  # ============================
143
  # Main Gradio Script
144
  # ============================
145
+ # as `run_inference` needs to be wrapped by `spaces.GPU` and the input can only be the prompt text
146
+ # so we can't pass the models to `run_inference` as arguments.
147
+ # instead, we need to define them globally so that we can access these models inside `run_inference`
148
+
149
  # read config
150
  args = parse_args()
151
  config = read_config(CONFIG_MAP[args.model_type])
 
181
  saved_path = save_sample(samples[0], fps=config.fps, save_path=filename)
182
  return saved_path
183
 
184
+ def main():
185
+ # create demo
186
+ with gr.Blocks() as demo:
187
+ with gr.Row():
188
+ with gr.Column():
189
+ gr.HTML(
190
+ """
191
+ <div style='text-align: center;'>
192
+ <p align="center">
193
+ <img src="https://github.com/hpcaitech/Open-Sora/raw/main/assets/readme/icon.png" width="250"/>
194
+ </p>
195
+ <div style="display: flex; gap: 10px; justify-content: center;">
196
+ <a href="https://github.com/hpcaitech/Open-Sora/stargazers"><img src="https://img.shields.io/github/stars/hpcaitech/Open-Sora?style=social"></a>
197
+ <a href="https://hpcaitech.github.io/Open-Sora/"><img src="https://img.shields.io/badge/Gallery-View-orange?logo=&amp"></a>
198
+ <a href="https://discord.gg/kZakZzrSUT"><img src="https://img.shields.io/badge/Discord-join-blueviolet?logo=discord&amp"></a>
199
+ <a href="https://join.slack.com/t/colossalaiworkspace/shared_invite/zt-247ipg9fk-KRRYmUl~u2ll2637WRURVA"><img src="https://img.shields.io/badge/Slack-ColossalAI-blueviolet?logo=slack&amp"></a>
200
+ <a href="https://twitter.com/yangyou1991/status/1769411544083996787?s=61&t=jT0Dsx2d-MS5vS9rNM5e5g"><img src="https://img.shields.io/badge/Twitter-Discuss-blue?logo=twitter&amp"></a>
201
+ <a href="https://raw.githubusercontent.com/hpcaitech/public_assets/main/colossalai/img/WeChat.png"><img src="https://img.shields.io/badge/微信-小助手加群-green?logo=wechat&amp"></a>
202
+ <a href="https://hpc-ai.com/blog/open-sora-v1.0"><img src="https://img.shields.io/badge/Open_Sora-Blog-blue"></a>
203
+ </div>
204
+ <h1 style='margin-top: 5px;'>Open-Sora: Democratizing Efficient Video Production for All</h1>
205
  </div>
206
+ """
207
+ )
 
 
208
 
209
+ with gr.Row():
210
+ with gr.Column():
211
+ prompt_text = gr.Textbox(show_label=False, placeholder="Describe your video here", lines=4)
212
+ submit_button = gr.Button("Generate video")
213
 
214
+ with gr.Column():
215
+ output_video = gr.Video()
216
 
217
+ submit_button.click(fn=run_inference, inputs=[prompt_text], outputs=output_video)
218
 
219
+ gr.Examples(
220
+ examples=[
221
+ [
222
+ "The video captures the majestic beauty of a waterfall cascading down a cliff into a serene lake. The waterfall, with its powerful flow, is the central focus of the video. The surrounding landscape is lush and green, with trees and foliage adding to the natural beauty of the scene. The camera angle provides a bird's eye view of the waterfall, allowing viewers to appreciate the full height and grandeur of the waterfall. The video is a stunning representation of nature's power and beauty.",
223
+ ],
224
  ],
225
+ fn=run_inference,
226
+ inputs=[
227
+ prompt_text,
228
+ ],
229
+ outputs=[output_video],
230
+ cache_examples=True,
231
+ )
232
+
233
+ # launch
234
+ demo.launch(server_port=args.port, server_name=args.host, share=args.share)
235
+
236
 
237
+ if __name__ == '__main__':
238
+ main()
239