1- import glob
1+ import os
22import socket
33import struct
4- import os
54import sys
6- from typing import Literal , Dict , Optional
5+ from typing import Literal
76
87import cv2 as cv
98import numpy as np
109
1110from touchdesigner_plugin .constants import HOST , JPEG_ENCODE_QUALITY_PERCENT , PORT
12- from touchdesigner_plugin .utilities import get_random_image
1311
1412sys .path .append (os .path .join (os .path .dirname (__file__ ), ".." , ".." ))
1513
16- from utils .wrapper import StreamDiffusionWrapper
14+ from utils .wrapper import StreamDiffusionWrapper # noqa: E402
1715
1816CURRENT_DIR = os .path .dirname (os .path .abspath (__file__ ))
1917
@@ -25,7 +23,7 @@ def __init__(self):
2523 self .server_socket .listen (5 )
2624
2725 model_id_or_path : str = "KBlueLeaf/kohaku-v2.1"
28- lora_dict : Optional [ Dict [ str , float ]] = None
26+ lora_dict : dict [ str , float ] | None = None
2927 width : int = 512
3028 height : int = 512
3129 acceleration : Literal ["none" , "xformers" , "tensorrt" ] = "xformers"
@@ -54,12 +52,11 @@ def send_image(self, client_socket):
5452 # image = get_random_image(nb_circles=3, noise_background=False)
5553 image = np .array (self .stream ())
5654
57-
5855 # NOTE: decrease JPEG_ENCODE_QUALITY_PERCENT to increase performance
5956 _ , image_data = cv .imencode (
6057 ".jpg" , image , [int (cv .IMWRITE_JPEG_QUALITY ), JPEG_ENCODE_QUALITY_PERCENT ]
6158 )
62-
59+
6360 image_size = struct .pack ("!I" , len (image_data ))
6461 client_socket .send (image_size )
6562 client_socket .send (image_data .tobytes ())
@@ -78,7 +75,7 @@ def run(self):
7875 prompt = prompt ,
7976 num_inference_steps = 50 ,
8077 )
81-
78+
8279 # Send image to client
8380 self .send_image (client_socket )
8481
0 commit comments