File size: 2,069 Bytes
ab3d570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a7ed44
ab3d570
2a7ed44
ab3d570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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()