def __init__(self, redis_client: redis.client.Redis): timees = redis_client.get('redditUpdated').decode('UTF-8') print(timees) self.date_updated_reddit = float(timees) self.date_updated_twitter = False self.date_updated_coindesk = False self.redis_client = redis_client #self.preprocessor = Preprocessor(self.redis_client) self.analyzer = Analyzer(self.redis_client)
def detection_worker(rds: redis.client.Redis, latest_timestamps: Dict[str, str]): whose_turn = "A" # Load the TFLite model and allocate tensors. interpreter = tflite.Interpreter(model_path="tflite/model.tflite") interpreter.allocate_tensors() _, height, width, _ = interpreter.get_input_details()[0]['shape'] while True: # rotate turn whose_turn = "B" if whose_turn == "A" else "A" # get image from A using redis latest_timestamp = latest_timestamps[whose_turn] image_bytes = rds.get(f"sentry.{whose_turn}.raw_images.{latest_timestamp}") if image_bytes is None: continue image = Image.open(io.BytesIO(image_bytes)).convert("RGB").resize((width, height), Image.ANTIALIAS) output_details = interpreter.get_output_details() tensor_index = interpreter.get_input_details()[0]["index"] input_tensor = interpreter.tensor(tensor_index)()[0] input_tensor[:, :] = image interpreter.invoke() boxes = interpreter.get_tensor(output_details[0]['index']) classes = interpreter.get_tensor(output_details[1]['index']) scores = interpreter.get_tensor(output_details[2]['index']) try: font = ImageFont.truetype("/usr/share/fonts/truetype/liberation/LiberationSansNarrow-Regular.ttf", 25) except IOError: print("Font not found, using default font.") font = ImageFont.load_default() draw_bounding_box_on_image(image,*boxes[0], list(ImageColor.colormap.values())[0], font, display_str_list=[str(round(scores[0]*10))+"%"]) await rds.set(f"sentry.{whose_turn}.processed_image", image.tobytes())
def redis_get(name: Any, connector: redis.client.Redis) -> Any: value = connector.get(name) if type(value) is bytes: value = pickle.loads(value) return value