Skip to content

Commit 0fc4aab

Browse files
committed
style
1 parent 2be7bca commit 0fc4aab

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

examples/research_projects/anytext/anytext.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
3030

3131
import cv2
32-
import huggingface_hub
3332
import numpy as np
3433
import PIL.Image
3534
import torch
3635
import torch.nn.functional as F
3736
from bert_tokenizer import BasicTokenizer
3837
from easydict import EasyDict as edict
39-
from diffusers.utils.constants import HF_MODULES_CACHE
4038
from frozen_clip_embedder_t3 import FrozenCLIPEmbedderT3
39+
from huggingface_hub import hf_hub_download
4140
from ocr_recog.RecModel import RecModel
4241
from PIL import Image, ImageDraw, ImageFont
4342
from safetensors.torch import load_file
@@ -68,10 +67,8 @@
6867
scale_lora_layers,
6968
unscale_lora_layers,
7069
)
70+
from diffusers.utils.constants import HF_MODULES_CACHE
7171
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
7572

7673

7774
checker = BasicTokenizer()
@@ -158,7 +155,7 @@ def __init__(
158155
proj_dir = hf_hub_download(
159156
repo_id="tolgacangoz/anytext",
160157
filename="text_embedding_module/proj.safetensors",
161-
cache_dir=HF_MODULES_CACHE
158+
cache_dir=HF_MODULES_CACHE,
162159
)
163160
self.proj.load_state_dict(load_file(proj_dir, device=str(embedder.device)))
164161
if use_fp16:
@@ -281,7 +278,7 @@ def create_predictor(model_dir=None, model_lang="ch", device="cpu", use_fp16=Fal
281278
model_dir = hf_hub_download(
282279
repo_id="tolgacangoz/anytext",
283280
filename="text_embedding_module/OCR/ppv3_rec.pth",
284-
cache_dir=HF_MODULES_CACHE
281+
cache_dir=HF_MODULES_CACHE,
285282
)
286283
if not os.path.exists(model_dir):
287284
raise ValueError("not find model file path {}".format(model_dir))
@@ -482,7 +479,7 @@ def __init__(self, font_path, use_fp16=False, device="cpu"):
482479
args["rec_char_dict_path"] = hf_hub_download(
483480
repo_id="tolgacangoz/anytext",
484481
filename="text_embedding_module/OCR/ppocr_keys_v1.txt",
485-
cache_dir=HF_MODULES_CACHE
482+
cache_dir=HF_MODULES_CACHE,
486483
)
487484
args["use_fp16"] = use_fp16
488485
self.embedding_manager.recog = TextRecognizer(args, self.text_predictor)
@@ -603,7 +600,7 @@ def forward(
603600

604601
self.embedding_manager.encode_text(text_info)
605602
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
607604
)
608605

609606
return prompt_embeds, negative_prompt_embeds, text_info, np_hint

0 commit comments

Comments
 (0)