|
import os |
|
os.system('pip install dashscope') |
|
import gradio as gr |
|
from http import HTTPStatus |
|
import dashscope |
|
from dashscope import VideoSynthesis |
|
|
|
DASHSCOPE_API_KEY = os.getenv('DASHSCOPE_API_KEY') |
|
dashscope.api_key = DASHSCOPE_API_KEY |
|
|
|
def video_generation(prompt): |
|
try: |
|
rsp = VideoSynthesis.call(model="wanx2.1-t2v-plus", prompt=prompt, watermark_wanx=True) |
|
video_url = rsp.output.video_url |
|
return video_url |
|
except Exception as e: |
|
gr.Warning(f"Warning: {e}") |
|
return None |
|
|
|
|
|
examples = [ |
|
'a tiny astronaut hatching from an egg on the moon', |
|
'A close-up of a panda wearing red clothes and holding a green sign with the words "Wanx" in both hands. The background is a busy city street with cars driving fast on the road.', |
|
'远景拍摄,塞纳河畔,绚烂的烟花在空中绽放,烟花形成了粉色数字“2025”时镜头拉近特写,然后逐渐消散', |
|
] |
|
css = """ |
|
#col-container { |
|
margin: 0 auto; |
|
max-width: 800px; |
|
} |
|
""" |
|
|
|
with gr.Blocks(css=css) as demo: |
|
with gr.Column(elem_id="col-container"): |
|
gr.Markdown(f"""# WanX 2.1 (Tongyi Wanxiang 2.1), the latest powerful text to video generation model developed by the WanX Team from Tongyi Lab, Alibaba Group. |
|
[[YouTube Videos]](https://www.youtube.com/watch?v=bq4nAVbYQQU) |
|
[[WanX WEB]](https://tongyi.aliyun.com/wanxiang/videoCreation) |
|
""") |
|
|
|
with gr.Row(): |
|
prompt = gr.Text( |
|
label="Prompt", |
|
show_label=False, |
|
max_lines=100, |
|
min_width=320, |
|
placeholder="Enter your prompt", |
|
container=False, |
|
) |
|
run_button = gr.Button("Run", scale=0) |
|
|
|
result = gr.Video(label="Generated video", show_label=False) |
|
gr.Examples( |
|
examples=examples, |
|
inputs=[prompt] |
|
) |
|
|
|
gr.on( |
|
triggers=[run_button.click], |
|
fn=video_generation, |
|
inputs=[prompt], |
|
outputs=[result] |
|
) |
|
|
|
demo.queue(max_size=10) |
|
demo.launch() |