|
29 | 29 | from typing import Any, Callable, Dict, List, Optional, Tuple, Union |
30 | 30 |
|
31 | 31 | import cv2 |
32 | | -import huggingface_hub |
33 | 32 | import numpy as np |
34 | 33 | import PIL.Image |
35 | 34 | import torch |
36 | 35 | import torch.nn.functional as F |
37 | 36 | from bert_tokenizer import BasicTokenizer |
38 | 37 | from easydict import EasyDict as edict |
39 | | -from diffusers.utils.constants import HF_MODULES_CACHE |
40 | 38 | from frozen_clip_embedder_t3 import FrozenCLIPEmbedderT3 |
| 39 | +from huggingface_hub import hf_hub_download |
41 | 40 | from ocr_recog.RecModel import RecModel |
42 | 41 | from PIL import Image, ImageDraw, ImageFont |
43 | 42 | from safetensors.torch import load_file |
|
68 | 67 | scale_lora_layers, |
69 | 68 | unscale_lora_layers, |
70 | 69 | ) |
| 70 | +from diffusers.utils.constants import HF_MODULES_CACHE |
71 | 71 | from diffusers.utils.torch_utils import is_compiled_module, is_torch_version, randn_tensor |
72 | | -from diffusers.configuration_utils import register_to_config, ConfigMixin |
73 | | -from diffusers.models.modeling_utils import ModelMixin |
74 | | -from huggingface_hub import hf_hub_download |
75 | 72 |
|
76 | 73 |
|
77 | 74 | checker = BasicTokenizer() |
@@ -158,7 +155,7 @@ def __init__( |
158 | 155 | proj_dir = hf_hub_download( |
159 | 156 | repo_id="tolgacangoz/anytext", |
160 | 157 | filename="text_embedding_module/proj.safetensors", |
161 | | - cache_dir=HF_MODULES_CACHE |
| 158 | + cache_dir=HF_MODULES_CACHE, |
162 | 159 | ) |
163 | 160 | self.proj.load_state_dict(load_file(proj_dir, device=str(embedder.device))) |
164 | 161 | if use_fp16: |
@@ -281,7 +278,7 @@ def create_predictor(model_dir=None, model_lang="ch", device="cpu", use_fp16=Fal |
281 | 278 | model_dir = hf_hub_download( |
282 | 279 | repo_id="tolgacangoz/anytext", |
283 | 280 | filename="text_embedding_module/OCR/ppv3_rec.pth", |
284 | | - cache_dir=HF_MODULES_CACHE |
| 281 | + cache_dir=HF_MODULES_CACHE, |
285 | 282 | ) |
286 | 283 | if not os.path.exists(model_dir): |
287 | 284 | raise ValueError("not find model file path {}".format(model_dir)) |
@@ -482,7 +479,7 @@ def __init__(self, font_path, use_fp16=False, device="cpu"): |
482 | 479 | args["rec_char_dict_path"] = hf_hub_download( |
483 | 480 | repo_id="tolgacangoz/anytext", |
484 | 481 | filename="text_embedding_module/OCR/ppocr_keys_v1.txt", |
485 | | - cache_dir=HF_MODULES_CACHE |
| 482 | + cache_dir=HF_MODULES_CACHE, |
486 | 483 | ) |
487 | 484 | args["use_fp16"] = use_fp16 |
488 | 485 | self.embedding_manager.recog = TextRecognizer(args, self.text_predictor) |
@@ -603,7 +600,7 @@ def forward( |
603 | 600 |
|
604 | 601 | self.embedding_manager.encode_text(text_info) |
605 | 602 | negative_prompt_embeds = self.frozen_CLIP_embedder_t3.encode( |
606 | | - [negative_prompt or ''], embedding_manager=self.embedding_manager |
| 603 | + [negative_prompt or ""], embedding_manager=self.embedding_manager |
607 | 604 | ) |
608 | 605 |
|
609 | 606 | return prompt_embeds, negative_prompt_embeds, text_info, np_hint |
|
0 commit comments