Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added progress bar to image generation #211

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions demos/paint_your_dreams_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
import openvino as ov
import openvino_genai as genai
import tqdm
from PIL import Image
from huggingface_hub import snapshot_download
from optimum.intel.openvino import OVModelForImageClassification
Expand Down Expand Up @@ -117,6 +118,20 @@ async def stop():
stop_generating = True


progress_bar = None
def progress(step, num_steps, latent):
global progress_bar
if progress_bar is None:
progress_bar = tqdm.tqdm(total=num_steps)

progress_bar.update()

if step == num_steps - 1:
progress_bar = None

return False


async def generate_images(input_image: np.ndarray, prompt: str, seed: int, size: int, guidance_scale: float, num_inference_steps: int,
strength: float, randomize_seed: bool, device: str, endless_generation: bool) -> tuple[np.ndarray, float]:
global stop_generating
Expand All @@ -130,14 +145,14 @@ async def generate_images(input_image: np.ndarray, prompt: str, seed: int, size:
if input_image is None:
ov_pipeline = await load_pipeline(hf_model_name, device, size, "text2image")
result = ov_pipeline.generate(prompt=prompt, num_inference_steps=num_inference_steps, width=size, height=size,
guidance_scale=guidance_scale, rng_seed=seed).data[0]
guidance_scale=guidance_scale, rng_seed=seed, callback=progress).data[0]
else:
ov_pipeline = await load_pipeline(hf_model_name, device, size,"image2image")
# ensure image is square
input_image = utils.crop_center(input_image)
input_image = cv2.resize(input_image, (size, size))
result = ov_pipeline.generate(prompt=prompt, image=ov.Tensor(input_image[None]), num_inference_steps=num_inference_steps, width=size, height=size,
guidance_scale=guidance_scale, strength=1.0 - strength, rng_seed=seed).data[0]
guidance_scale=guidance_scale, strength=1.0 - strength, rng_seed=seed, callback=progress).data[0]
end_time = time.time()

label = safety_checker(Image.fromarray(result), top_k=1)
Expand Down
1 change: 1 addition & 0 deletions demos/paint_your_dreams_demo/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pillow==11.1.0
opencv-python==4.10.0.84
numpy==2.1.3
gradio==5.12.0
tqdm==4.67.1
Loading