Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,20 @@
|
|
| 1 |
-
import
|
| 2 |
-
import torch
|
| 3 |
-
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
-
|
| 6 |
-
from diffusers.utils import export_to_video
|
| 7 |
-
from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXConditionPipeline, LTXVideoCondition
|
| 8 |
|
| 9 |
-
|
| 10 |
-
transformer = AutoModel.from_pretrained(
|
| 11 |
-
"Lightricks/LTX-Video",
|
| 12 |
-
subfolder="transformer",
|
| 13 |
torch_dtype=torch.bfloat16,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
transformer=transformer,
|
| 22 |
-
torch_dtype=torch.bfloat16,
|
| 23 |
-
).to("cuda")
|
| 24 |
-
|
| 25 |
-
NEGATIVE = "worst quality, inconsistent motion, blurry, jittery, distorted"
|
| 26 |
-
|
| 27 |
-
def generate(image: Image.Image, prompt: str, use_shift: bool, mu: float):
|
| 28 |
-
cond = LTXVideoCondition(image=image, frame_index=0, strength=1.0)
|
| 29 |
-
kwargs = dict(
|
| 30 |
-
conditions=[cond],
|
| 31 |
-
prompt=prompt,
|
| 32 |
-
negative_prompt=NEGATIVE,
|
| 33 |
-
width=480,
|
| 34 |
-
height=480,
|
| 35 |
-
num_frames=81,
|
| 36 |
-
num_inference_steps=50,
|
| 37 |
-
)
|
| 38 |
-
# Caminho simples: desativa shifting por padrão
|
| 39 |
-
if use_shift:
|
| 40 |
-
kwargs["use_dynamic_shifting"] = True
|
| 41 |
-
kwargs["mu"] = mu
|
| 42 |
-
else:
|
| 43 |
-
kwargs["use_dynamic_shifting"] = False
|
| 44 |
-
|
| 45 |
-
result = pipeline(**kwargs)
|
| 46 |
-
video = result.frames[0]
|
| 47 |
-
export_to_video(video, "output.mp4", fps=24)
|
| 48 |
-
return "output.mp4"
|
| 49 |
-
|
| 50 |
-
with gr.Blocks(title="LTX-Video (Simple)", theme=gr.themes.Soft()) as demo:
|
| 51 |
-
in_image = gr.Image(type="pil", label="Imagem de entrada")
|
| 52 |
-
in_prompt = gr.Textbox(label="Prompt", placeholder="Descreva...")
|
| 53 |
-
use_shift = gr.Checkbox(value=False, label="Dynamic shifting (qnprevisa)")
|
| 54 |
-
mu = gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="mu")
|
| 55 |
-
run_button = gr.Button("Gerar Vídeo", variant="primary")
|
| 56 |
-
video_out = gr.Video(label="Vídeo Gerado")
|
| 57 |
-
|
| 58 |
-
run_button.click(fn=generate, inputs=[in_image, in_prompt, use_shift, mu], outputs=[video_out])
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
-
demo.queue().launch(
|
| 62 |
-
server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
|
| 63 |
-
server_port=int(os.getenv("GRADIO_SERVER_PORT", "7861")),
|
| 64 |
-
show_error=True,
|
| 65 |
-
)
|
|
|
|
| 1 |
+
from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig
|
|
|
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
+
import torch
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
pipe = QwenImagePipeline.from_pretrained(
|
|
|
|
|
|
|
|
|
|
| 6 |
torch_dtype=torch.bfloat16,
|
| 7 |
+
device="cuda",
|
| 8 |
+
model_configs=[
|
| 9 |
+
ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),
|
| 10 |
+
ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"),
|
| 11 |
+
ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
|
| 12 |
+
],
|
| 13 |
+
tokenizer_config=ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="tokenizer/"),
|
| 14 |
)
|
| 15 |
+
prompt = "A detailed portrait of a girl underwater, wearing a blue flowing dress, hair gently floating, clear light and shadow, surrounded by bubbles, calm expression, fine details, dreamy and beautiful."
|
| 16 |
+
image = pipe(
|
| 17 |
+
prompt, seed=0, num_inference_steps=40,
|
| 18 |
+
# edit_image=Image.open("xxx.jpg").resize((1328, 1328)) # For Qwen-Image-Edit
|
| 19 |
+
)
|
| 20 |
+
image.save("image.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|