imseldrith commited on
Commit
45acbba
·
verified ·
1 Parent(s): 6dcb2fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+ from gradio_client import Client
5
+
6
+ gurl=os.environ.get("GURL")
7
+ concurrency_limit =int(os.environ.get("CLIMIT"))
8
+ client = Client(gurl)
9
+
10
+ def gen_prompt(prompt):
11
+ result = client.predict(
12
+ prompt,
13
+ fn_index=0
14
+ )
15
+ return result
16
+
17
+ def gen_video(prompt1, prompt2):
18
+ if prompt2 == "":
19
+ prompt2 = prompt1
20
+ print('P1:',prompt1,'P2:',prompt2)
21
+ result = client.predict(
22
+ prompt1,
23
+ prompt2,
24
+ fn_index=1
25
+ )
26
+ return result
27
+
28
+
29
+ def videocrafter_demo():
30
+ with gr.Blocks(analytics_enabled=False) as videocrafter_iface:
31
+ gr.HTML("<div align='center'> <h2> VideoCrafter2: Overcoming Data Limitations for High-Quality Video Diffusion Models </h2> \
32
+ <a style='font-size:18px;color: #000000' href='https://github.com/AILab-CVC/VideoCrafter'> Github </a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
33
+ <a style='font-size:18px;color: #000000' href='https://ailab-cvc.github.io/videocrafter'> Homepage </a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
34
+ <a style='font-size:18px;color: #000000' href='https://discord.gg/RQENrunu92'> Discord </a> </div>")
35
+ gr.Markdown("""
36
+ <b>1. User can enter a short text and then generate a rich prompt by clicking on the Expand Prompt button.<br>2. Two videos will be generated based on the original user input and the rich prompt respectively.<br>3. It will take 2-3 minutes to generate the HD videos.</b> \
37
+ """)
38
+
39
+ #######t2v#######
40
+ with gr.Tab(label="Text2Video"):
41
+ with gr.Column():
42
+ with gr.Row():
43
+ with gr.Column():
44
+ input_text = gr.Text(label='User Input')
45
+ prompt_btn = gr.Button("Expand Prompt")
46
+ output_text = gr.Text(label='Rich Prompt')
47
+ video_btn = gr.Button("Generate Videos")
48
+ with gr.Tab(label='Results'):
49
+ with gr.Row():
50
+ output_video_1 = gr.Video(width=512, label='User Input')
51
+ output_video_2 = gr.Video(width=512,label='Rich Prompt')
52
+ prompt_btn.click(
53
+ fn=gen_prompt,
54
+ inputs=[input_text],
55
+ outputs=[output_text,input_text],
56
+ concurrency_limit=1
57
+ )
58
+ video_btn.click(
59
+ fn=gen_video,
60
+ inputs=[input_text, output_text],
61
+ outputs=[output_video_1, output_video_2],
62
+ concurrency_limit=concurrency_limit
63
+ )
64
+
65
+
66
+ return videocrafter_iface
67
+
68
+ if __name__ == "__main__":
69
+ videocrafter_iface = videocrafter_demo()
70
+ videocrafter_iface.queue()
71
+ videocrafter_iface.launch()