Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.system('pip install dashscope')
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from http import HTTPStatus
|
| 5 |
+
import dashscope
|
| 6 |
+
from dashscope import VideoSynthesis
|
| 7 |
+
|
| 8 |
+
DASHSCOPE_API_KEY = os.getenv('DASHSCOPE_API_KEY')
|
| 9 |
+
dashscope.api_key = DASHSCOPE_API_KEY
|
| 10 |
+
|
| 11 |
+
def video_generation(prompt):
|
| 12 |
+
try:
|
| 13 |
+
rsp = VideoSynthesis.call(model="wanx2.1-t2v-plus", prompt=prompt, watermark_wanx=True)
|
| 14 |
+
video_url = rsp.output.video_url
|
| 15 |
+
return video_url
|
| 16 |
+
except Exception as e:
|
| 17 |
+
gr.Warning(f"Warning: {e}")
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
examples = [
|
| 22 |
+
'a tiny astronaut hatching from an egg on the moon',
|
| 23 |
+
'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.',
|
| 24 |
+
'远景拍摄,塞纳河畔,绚烂的烟花在空中绽放,烟花形成了粉色数字“2025”时镜头拉近特写,然后逐渐消散',
|
| 25 |
+
]
|
| 26 |
+
css = """
|
| 27 |
+
#col-container {
|
| 28 |
+
margin: 0 auto;
|
| 29 |
+
max-width: 800px;
|
| 30 |
+
}
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
with gr.Blocks(css=css) as demo:
|
| 34 |
+
with gr.Column(elem_id="col-container"):
|
| 35 |
+
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.
|
| 36 |
+
[[YouTube Videos]](https://www.youtube.com/watch?v=bq4nAVbYQQU)
|
| 37 |
+
[[Wanx WEB]](https://tongyi.aliyun.com/wanxiang/videoCreation)
|
| 38 |
+
""")
|
| 39 |
+
|
| 40 |
+
with gr.Row():
|
| 41 |
+
prompt = gr.Text(
|
| 42 |
+
label="Prompt",
|
| 43 |
+
show_label=False,
|
| 44 |
+
max_lines=100,
|
| 45 |
+
min_width=320,
|
| 46 |
+
placeholder="Enter your prompt",
|
| 47 |
+
container=False,
|
| 48 |
+
)
|
| 49 |
+
run_button = gr.Button("Run", scale=0)
|
| 50 |
+
|
| 51 |
+
result = gr.Video(label="Generated video", show_label=False)
|
| 52 |
+
gr.Examples(
|
| 53 |
+
examples=examples,
|
| 54 |
+
inputs=[prompt]
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
gr.on(
|
| 58 |
+
triggers=[run_button.click],
|
| 59 |
+
fn=video_generation,
|
| 60 |
+
inputs=[prompt],
|
| 61 |
+
outputs=[result]
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
demo.queue(max_size=10)
|
| 65 |
+
demo.launch()
|