Spaces:
Running
Running
Update gradio_app.py
Browse files- gradio_app.py +64 -25
gradio_app.py
CHANGED
|
@@ -2,6 +2,7 @@ import yaml
|
|
| 2 |
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
|
|
|
| 5 |
import torch
|
| 6 |
import imageio
|
| 7 |
import argparse
|
|
@@ -249,8 +250,14 @@ def main(args):
|
|
| 249 |
print(f"relight with bg generation! prompt:{relight_prompt}, light:{bg_source.value}, save in {results_path}.")
|
| 250 |
return results_path
|
| 251 |
|
| 252 |
-
def infer(n_prompt, relight_prompt, video_path, bg_source,
|
| 253 |
-
width, height, strength, gamma, num_step, text_guide_scale, seed):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
config_data = {
|
| 256 |
"n_prompt": n_prompt,
|
|
@@ -287,28 +294,60 @@ def infer(n_prompt, relight_prompt, video_path, bg_source, save_path,
|
|
| 287 |
return results_path
|
| 288 |
|
| 289 |
with gr.Blocks() as demo:
|
| 290 |
-
with gr.
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
| 313 |
|
| 314 |
-
demo.launch()
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
+
import shutil
|
| 6 |
import torch
|
| 7 |
import imageio
|
| 8 |
import argparse
|
|
|
|
| 250 |
print(f"relight with bg generation! prompt:{relight_prompt}, light:{bg_source.value}, save in {results_path}.")
|
| 251 |
return results_path
|
| 252 |
|
| 253 |
+
def infer(n_prompt, relight_prompt, video_path, bg_source,
|
| 254 |
+
width, height, strength, gamma, num_step, text_guide_scale, seed, progress=gr.Progress(track_tqdm=True)):
|
| 255 |
+
|
| 256 |
+
save_path = "./output"
|
| 257 |
+
# Ensure output folder is empty
|
| 258 |
+
if os.path.exists(save_path):
|
| 259 |
+
shutil.rmtree(save_path)
|
| 260 |
+
os.makedirs(save_path, exist_ok=True)
|
| 261 |
|
| 262 |
config_data = {
|
| 263 |
"n_prompt": n_prompt,
|
|
|
|
| 294 |
return results_path
|
| 295 |
|
| 296 |
with gr.Blocks() as demo:
|
| 297 |
+
with gr.Column(elem_id="col-container"):
|
| 298 |
+
gr.Markdown("# Light-A-Video")
|
| 299 |
+
with gr.Row():
|
| 300 |
+
with gr.Column():
|
| 301 |
+
video_path = gr.Textbox(label="Video Path")
|
| 302 |
+
with gr.Row():
|
| 303 |
+
relight_prompt = gr.Textbox(label="Relight Prompt")
|
| 304 |
+
bg_source = gr.Dropdown(["NONE", "LEFT", "RIGHT", "BOTTOM", "TOP"], label="Background Source")
|
| 305 |
+
|
| 306 |
+
with gr.Accordion(label="Advanced Settings", open=False):
|
| 307 |
+
n_prompt = gr.Textbox(label="Negative Prompt", value="bad quality, worse quality")
|
| 308 |
+
with gr.Row():
|
| 309 |
+
width = gr.Number(label="Width", value=512)
|
| 310 |
+
height = gr.Number(label="Height", value=512)
|
| 311 |
+
|
| 312 |
+
with gr.Row():
|
| 313 |
+
strength = gr.Slider(minimum=0.0, maximum=1.0, label="Strength", value=0.5)
|
| 314 |
+
gamma = gr.Slider(minimum=0.0, maximum=1.0, label="Gamma", value=0.5)
|
| 315 |
+
with gr.Row():
|
| 316 |
+
num_step = gr.Number(label="Number of Steps", value=25)
|
| 317 |
+
text_guide_scale = gr.Number(label="Text Guide Scale", value=2)
|
| 318 |
+
seed = gr.Number(label="Seed", value=2060)
|
| 319 |
+
|
| 320 |
+
submit = gr.Button("Run")
|
| 321 |
+
|
| 322 |
+
gr.Examples(
|
| 323 |
+
examples=[
|
| 324 |
+
["./input_animatediff/bear.mp4", "a bear walking on the rock, nature lighting, key light", "TOP"],
|
| 325 |
+
["./input_animatediff/boat.mp4", "a boat floating on the sea, sunset", "TOP"],
|
| 326 |
+
["./input_animatediff/car.mp4", "a car driving on the street, neon light", "RIGHT"],
|
| 327 |
+
["./input_animatediff/cat.mp4", "a cat, red and blue neon light", "LEFT"],
|
| 328 |
+
["./input_animatediff/cow.mp4", "a cow drinking water in the river, sunset", "RIGHT"],
|
| 329 |
+
["./input_animatediff/flowers.mp4", "A basket of flowers, sunshine, hard light", "LEFT"],
|
| 330 |
+
["./input_animatediff/fox.mp4", "a fox, sunlight filtering through trees, dappled light", "LEFT"],
|
| 331 |
+
["./input_animatediff/girl.mp4", "a girl, magic lit, sci-fi RGB glowing, key lighting", "BOTTOM"],
|
| 332 |
+
["./input_animatediff/girl2.mp4", "an anime girl, neon light", "RIGHT"],
|
| 333 |
+
["./input_animatediff/juice.mp4", "Pour juice into a glass, magic golden lit", "RIGHT"],
|
| 334 |
+
["./input_animatediff/man2.mp4", "handsome man with glasses, shadow from window, sunshine", "RIGHT"],
|
| 335 |
+
["./input_animatediff/man4.mp4", "handsome man with glasses, sunlight through the blinds", "LEFT"],
|
| 336 |
+
["./input_animatediff/plane.mp4", "a plane on the runway, bottom neon light", "BOTTOM"],
|
| 337 |
+
["./input_animatediff/toy.mp4", "a maneki-neko toy, cozy bedroom illumination", "RIGHT"],
|
| 338 |
+
["./input_animatediff/woman.mp4", "a woman with curly hair, natural lighting, warm atmosphere", "LEFT"],
|
| 339 |
+
],
|
| 340 |
+
inputs=[video_path, relight_prompt, bg_source]
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
with gr.Column():
|
| 344 |
+
output = gr.Video(label="Results Path")
|
| 345 |
|
| 346 |
+
submit.click(
|
| 347 |
+
fn=infer,
|
| 348 |
+
inputs=[n_prompt, relight_prompt, video_path, bg_source,
|
| 349 |
+
width, height, strength, gamma, num_step, text_guide_scale, seed],
|
| 350 |
+
outputs=[output]
|
| 351 |
+
)
|
| 352 |
|
| 353 |
+
demo.queue().launch(show_api=False, show_error=True, ssr_mode=False)
|