AlekseyCalvin commited on
Commit
2bee297
1 Parent(s): bcee7ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -8,9 +8,11 @@ from PIL import Image
8
  import spaces
9
  from diffusers import DiffusionPipeline, AutoPipelineForText2Image
10
  from diffusers import StableDiffusion3Pipeline, FlowMatchEulerDiscreteScheduler, SD3Transformer2DModel # pip install diffusers>=0.31.0
 
11
  import copy
12
  import random
13
  import time
 
14
  from huggingface_hub import login, hf_hub_download
15
  import safetensors.torch
16
  from safetensors.torch import load_file
@@ -38,6 +40,24 @@ with open('loras.json', 'r') as f:
38
  #base_model = "stabilityai/stable-diffusion-3.5-large"
39
  pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  #pipe.transformer.to(memory_format=torch.channels_last)
42
  #pipe.vae.to(memory_format=torch.channels_last)
43
 
 
8
  import spaces
9
  from diffusers import DiffusionPipeline, AutoPipelineForText2Image
10
  from diffusers import StableDiffusion3Pipeline, FlowMatchEulerDiscreteScheduler, SD3Transformer2DModel # pip install diffusers>=0.31.0
11
+ from transformers import CLIPModel, CLIPProcessor, CLIPTextModel, CLIPTokenizer, CLIPConfig, T5EncoderModel, T5Tokenizer
12
  import copy
13
  import random
14
  import time
15
+ from huggingface_hub import HfFileSystem, ModelCard
16
  from huggingface_hub import login, hf_hub_download
17
  import safetensors.torch
18
  from safetensors.torch import load_file
 
40
  #base_model = "stabilityai/stable-diffusion-3.5-large"
41
  pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
42
 
43
+ clipmodel = 'norm'
44
+ if clipmodel == "long":
45
+ model_id = "zer0int/LongCLIP-GmP-ViT-L-14"
46
+ config = CLIPConfig.from_pretrained(model_id)
47
+ maxtokens = 248
48
+ if clipmodel == "norm":
49
+ model_id = "zer0int/CLIP-GmP-ViT-L-14"
50
+ config = CLIPConfig.from_pretrained(model_id)
51
+ maxtokens = 77
52
+ clip_model = CLIPModel.from_pretrained(model_id, torch_dtype=torch.bfloat16, config=config, ignore_mismatched_sizes=True).to("cuda")
53
+ clip_processor = CLIPProcessor.from_pretrained(model_id, padding="max_length", max_length=maxtokens, ignore_mismatched_sizes=True, return_tensors="pt", truncation=True)
54
+
55
+ pipe.tokenizer = clip_processor.tokenizer
56
+ pipe.text_encoder = clip_model.text_model
57
+ pipe.tokenizer_max_length = maxtokens
58
+ pipe.text_encoder.dtype = torch.bfloat16
59
+
60
+
61
  #pipe.transformer.to(memory_format=torch.channels_last)
62
  #pipe.vae.to(memory_format=torch.channels_last)
63