cleanup and local test
This commit is contained in:
committed by
SolitaryThinker
parent
2d7e262b13
commit
a0749e98fd
@@ -1,13 +1,4 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""
|
||||
GLM-Image inference example using FastVideo.
|
||||
|
||||
This example demonstrates how to generate images using the GLM-Image model
|
||||
through FastVideo's VideoGenerator API.
|
||||
|
||||
Usage:
|
||||
python examples/inference/basic/basic_glm_image.py
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
@@ -41,11 +32,12 @@ def main() -> None:
|
||||
height=1024,
|
||||
width=1024,
|
||||
num_inference_steps=50,
|
||||
guidance_scale=7.5,
|
||||
guidance_scale=1.5,
|
||||
)
|
||||
|
||||
if result and len(result) > 0:
|
||||
img = Image.fromarray(result[0])
|
||||
frames = result.get("frames") if isinstance(result, dict) else None
|
||||
if frames:
|
||||
img = Image.fromarray(frames[0])
|
||||
img.save(os.path.join(OUTPUT_PATH, "landscape.png"))
|
||||
print(f"Saved image to {OUTPUT_PATH}/landscape.png")
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import os
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from fastvideo import VideoGenerator
|
||||
|
||||
OUTPUT_PATH = "image_output"
|
||||
CONDITION_IMAGE = "assets/images/couple.jpg"
|
||||
|
||||
PROMPT = "Change the background to a snowy mountain landscape at golden hour."
|
||||
|
||||
|
||||
def main() -> None:
|
||||
generator = VideoGenerator.from_pretrained(
|
||||
"zai-org/GLM-Image",
|
||||
num_gpus=1,
|
||||
trust_remote_code=True,
|
||||
)
|
||||
|
||||
os.makedirs(OUTPUT_PATH, exist_ok=True)
|
||||
condition = Image.open(CONDITION_IMAGE).convert("RGB")
|
||||
|
||||
result = generator.generate_video(
|
||||
prompt=PROMPT,
|
||||
pil_image=condition,
|
||||
output_path=OUTPUT_PATH,
|
||||
save_video=False,
|
||||
return_frames=True,
|
||||
height=1024,
|
||||
width=1024,
|
||||
num_inference_steps=50,
|
||||
guidance_scale=1.5,
|
||||
)
|
||||
|
||||
frames = result.get("frames") if isinstance(result, dict) else None
|
||||
if frames:
|
||||
img = Image.fromarray(frames[0])
|
||||
img.save(os.path.join(OUTPUT_PATH, "edited.png"))
|
||||
print(f"Saved image to {OUTPUT_PATH}/edited.png")
|
||||
|
||||
generator.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user