Spaces:
Running
Running
update for working with duplicated instances only
Browse files
app.py
CHANGED
@@ -2,6 +2,10 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
import torch
|
|
|
|
|
|
|
|
|
5 |
import gc
|
6 |
from diffusers import AutoencoderKLCogVideoX, CogVideoXImageToVideoPipeline, CogVideoXTransformer3DModel
|
7 |
from diffusers.utils import export_to_video, load_image
|
@@ -131,8 +135,68 @@ def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True))
|
|
131 |
|
132 |
return final_path
|
133 |
|
134 |
-
# Set up Gradio
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
with gr.Column(elem_id="col-container"):
|
137 |
gr.Markdown("# DimensionX")
|
138 |
gr.Markdown("### Create Any 3D and 4D Scenes from a Single Image with Controllable Video Diffusion")
|
@@ -157,10 +221,52 @@ with gr.Blocks(analytics_enabled=False) as demo:
|
|
157 |
""")
|
158 |
with gr.Row():
|
159 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
image_in = gr.Image(label="Image Input", type="filepath")
|
161 |
prompt = gr.Textbox(label="Prompt")
|
162 |
orbit_type = gr.Radio(label="Orbit type", choices=["Left", "Up"], value="Left", interactive=True)
|
163 |
-
submit_btn = gr.Button("Submit")
|
164 |
with gr.Column():
|
165 |
video_out = gr.Video(label="Video output")
|
166 |
examples = gr.Examples(
|
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
import torch
|
5 |
+
|
6 |
+
is_shared_ui = True if "fffiloni/DimensionX" in os.environ['SPACE_ID'] else False
|
7 |
+
is_gpu_associated = torch.cuda.is_available()
|
8 |
+
|
9 |
import gc
|
10 |
from diffusers import AutoencoderKLCogVideoX, CogVideoXImageToVideoPipeline, CogVideoXTransformer3DModel
|
11 |
from diffusers.utils import export_to_video, load_image
|
|
|
135 |
|
136 |
return final_path
|
137 |
|
138 |
+
# Set up Gradio U
|
139 |
+
|
140 |
+
css = """
|
141 |
+
div#warning-duplicate {
|
142 |
+
background-color: #ebf5ff;
|
143 |
+
padding: 0 16px 16px;
|
144 |
+
margin: 20px 0;
|
145 |
+
color: #030303!important;
|
146 |
+
}
|
147 |
+
div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
|
148 |
+
color: #0f4592!important;
|
149 |
+
}
|
150 |
+
div#warning-duplicate strong {
|
151 |
+
color: #0f4592;
|
152 |
+
}
|
153 |
+
p.actions {
|
154 |
+
display: flex;
|
155 |
+
align-items: center;
|
156 |
+
margin: 20px 0;
|
157 |
+
}
|
158 |
+
div#warning-duplicate .actions a {
|
159 |
+
display: inline-block;
|
160 |
+
margin-right: 10px;
|
161 |
+
}
|
162 |
+
div#warning-setgpu {
|
163 |
+
background-color: #fff4eb;
|
164 |
+
padding: 0 16px 16px;
|
165 |
+
margin: 20px 0;
|
166 |
+
color: #030303!important;
|
167 |
+
}
|
168 |
+
div#warning-setgpu > .gr-prose > h2, div#warning-setgpu > .gr-prose > p {
|
169 |
+
color: #92220f!important;
|
170 |
+
}
|
171 |
+
div#warning-setgpu a, div#warning-setgpu b {
|
172 |
+
color: #91230f;
|
173 |
+
}
|
174 |
+
div#warning-setgpu p.actions > a {
|
175 |
+
display: inline-block;
|
176 |
+
background: #1f1f23;
|
177 |
+
border-radius: 40px;
|
178 |
+
padding: 6px 24px;
|
179 |
+
color: antiquewhite;
|
180 |
+
text-decoration: none;
|
181 |
+
font-weight: 600;
|
182 |
+
font-size: 1.2em;
|
183 |
+
}
|
184 |
+
div#warning-ready {
|
185 |
+
background-color: #ecfdf5;
|
186 |
+
padding: 0 16px 16px;
|
187 |
+
margin: 20px 0;
|
188 |
+
color: #030303!important;
|
189 |
+
}
|
190 |
+
div#warning-ready > .gr-prose > h2, div#warning-ready > .gr-prose > p {
|
191 |
+
color: #057857!important;
|
192 |
+
}
|
193 |
+
.custom-color {
|
194 |
+
color: #030303 !important;
|
195 |
+
}
|
196 |
+
"""
|
197 |
+
|
198 |
+
|
199 |
+
with gr.Blocks(css=css, analytics_enabled=False) as demo:
|
200 |
with gr.Column(elem_id="col-container"):
|
201 |
gr.Markdown("# DimensionX")
|
202 |
gr.Markdown("### Create Any 3D and 4D Scenes from a Single Image with Controllable Video Diffusion")
|
|
|
221 |
""")
|
222 |
with gr.Row():
|
223 |
with gr.Column():
|
224 |
+
|
225 |
+
if is_shared_ui:
|
226 |
+
top_description = gr.HTML(f'''
|
227 |
+
<div class="gr-prose">
|
228 |
+
<h2 class="custom-color"><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
229 |
+
Attention: this Space need to be duplicated to work</h2>
|
230 |
+
<p class="main-message custom-color">
|
231 |
+
To make it work, <strong>duplicate the Space</strong> and run it on your own profile using a <strong>private</strong> GPU (L40s recommended).<br />
|
232 |
+
A L40s costs <strong>US$1.80/h</strong>.
|
233 |
+
</p>
|
234 |
+
<p class="actions custom-color">
|
235 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
|
236 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
|
237 |
+
</a>
|
238 |
+
to start experimenting with this demo
|
239 |
+
</p>
|
240 |
+
</div>
|
241 |
+
''', elem_id="warning-duplicate")
|
242 |
+
else:
|
243 |
+
if(is_gpu_associated):
|
244 |
+
top_description = gr.HTML(f'''
|
245 |
+
<div class="gr-prose">
|
246 |
+
<h2 class="custom-color"><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
247 |
+
You have successfully associated a GPU to this Space 🎉</h2>
|
248 |
+
<p class="custom-color">
|
249 |
+
You will be billed by the minute from when you activated the GPU until when it is turned off.
|
250 |
+
</p>
|
251 |
+
</div>
|
252 |
+
''', elem_id="warning-ready")
|
253 |
+
else:
|
254 |
+
top_description = gr.HTML(f'''
|
255 |
+
<div class="gr-prose">
|
256 |
+
<h2 class="custom-color"><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
257 |
+
You have successfully duplicated the MimicMotion Space 🎉</h2>
|
258 |
+
<p class="custom-color">There's only one step left before you can properly play with this demo: <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a GPU</b> to it (via the Settings tab)</a> and run the app below.
|
259 |
+
You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
|
260 |
+
<p class="actions custom-color">
|
261 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">🔥 Set recommended GPU</a>
|
262 |
+
</p>
|
263 |
+
</div>
|
264 |
+
''', elem_id="warning-setgpu")
|
265 |
+
|
266 |
image_in = gr.Image(label="Image Input", type="filepath")
|
267 |
prompt = gr.Textbox(label="Prompt")
|
268 |
orbit_type = gr.Radio(label="Orbit type", choices=["Left", "Up"], value="Left", interactive=True)
|
269 |
+
submit_btn = gr.Button("Submit", interactive=False if is_shared_ui else True)
|
270 |
with gr.Column():
|
271 |
video_out = gr.Video(label="Video output")
|
272 |
examples = gr.Examples(
|