From 92bf193f1ad30f07199543c3c2170f424e9eedd8 Mon Sep 17 00:00:00 2001 From: reng Date: Wed, 16 Jul 2025 16:29:07 +0800 Subject: [PATCH] update --- img2img.py | 9 +++++---- main.py | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/img2img.py b/img2img.py index 5adaf98..f850fe0 100644 --- a/img2img.py +++ b/img2img.py @@ -78,7 +78,8 @@ class Pipeline: use_tiny_vae=True, device=device, dtype=torch_dtype, - t_index_list=[35, 45], + # t_index_list=[35, 45], + t_index_list=[1], frame_buffer_size=1, width=params.width, height=params.height, @@ -101,12 +102,12 @@ class Pipeline: prompt=default_prompt, negative_prompt=default_negative_prompt, num_inference_steps=50, - guidance_scale=1.2, + guidance_scale=1.0, ) def predict(self, image: Image.Image, params: "Pipeline.InputParams") -> Image.Image: - image_tensor = self.stream.preprocess_image(image) + # image_tensor = self.stream.preprocess_image(image) # output_image = self.stream(image=image_tensor, prompt=params.prompt) - output_image = self.stream(image=image_tensor, prompt=params.prompt) + output_image = self.stream(image=image, prompt=params.prompt) return output_image \ No newline at end of file diff --git a/main.py b/main.py index 627a68d..2db4b63 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ import SpoutGL from OpenGL.GL import GL_RGBA import time import img2img +from multiprocessing import Queue def main(): TARGET_FPS = 60 @@ -19,6 +20,8 @@ def main(): timestamp = datetime.datetime.now() fps = 30.0 + prompt_queue = Queue() + print("Initializing StreamDiffusion pipeline...") global pipeline try: @@ -39,6 +42,7 @@ def main(): async def update_prompt(update: PromptUpdate): global PROMPT PROMPT = update.prompt + prompt_queue.put(PROMPT) print(f"Prompt updated to: {PROMPT}") return {"message": "Prompt updated successfully", "new_prompt": PROMPT} @@ -77,11 +81,18 @@ def main(): if spout_receiver.isConnected() and SpoutGL.helpers.isBufferEmpty(image_bgra): continue - image_rgb_array = image_bgra[:, :, [2,1,0]] - input_image = Image.fromarray(image_rgb_array, 'RGB') + image_rgb_array = image_bgra[:, :, [2,1,0]] + # image_rgb_array = image_rgb_array.astype(np.float32) / 255.0 + input_image = Image.fromarray(image_rgb_array, 'RGB') # input_image.save("debug_input.png") + if not prompt_queue.empty(): + new_prompt = prompt_queue.get(block=False) + if new_prompt: + print(f"Received new prompt from queue: {new_prompt}") + PROMPT = new_prompt + # print(f"current prompt: {PROMPT}") params = img2img.Pipeline.InputParams(prompt=PROMPT) output_image = pipeline.predict(image=input_image, params=params) # output_image.save("debug_output.png")