Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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> Pixelgen v1</h2></div>")
|
32 |
+
gr.Markdown("""
|
33 |
+
<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> \
|
34 |
+
""")
|
35 |
+
|
36 |
+
#######t2v#######
|
37 |
+
with gr.Tab(label="Text to Video"):
|
38 |
+
with gr.Column():
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column():
|
41 |
+
input_text = gr.Text(label='User Input')
|
42 |
+
prompt_btn = gr.Button("Navigate Prompt")
|
43 |
+
output_text = gr.Text(label='Rich Prompt')
|
44 |
+
video_btn = gr.Button("Generate Videos")
|
45 |
+
with gr.Tab(label='Results'):
|
46 |
+
with gr.Row():
|
47 |
+
output_video_1 = gr.Video(width=512, label='User Input')
|
48 |
+
output_video_2 = gr.Video(width=512,label='Navigate Prompt')
|
49 |
+
prompt_btn.click(
|
50 |
+
fn=gen_prompt,
|
51 |
+
inputs=[input_text],
|
52 |
+
outputs=[output_text,input_text],
|
53 |
+
concurrency_limit=1
|
54 |
+
)
|
55 |
+
video_btn.click(
|
56 |
+
fn=gen_video,
|
57 |
+
inputs=[input_text, output_text],
|
58 |
+
outputs=[output_video_1, output_video_2],
|
59 |
+
concurrency_limit=concurrency_limit
|
60 |
+
)
|
61 |
+
|
62 |
+
|
63 |
+
return videocrafter_iface
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
videocrafter_iface = videocrafter_demo()
|
67 |
+
videocrafter_iface.queue()
|
68 |
+
videocrafter_iface.launch()
|