alfredplpl commited on
Commit
a00ca4e
1 Parent(s): b05f041

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -5,6 +5,7 @@ import torch
5
  from PIL import Image
6
  import random
7
  import os
 
8
 
9
 
10
  model_id = 'aipicasso/picasso-diffusion-1-0-demo'
@@ -32,6 +33,27 @@ pipe_i2i=pipe_i2i_merged.to("cuda")
32
  pipe.enable_xformers_memory_efficient_attention()
33
  pipe_i2i.enable_xformers_memory_efficient_attention()
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  def error_str(error, title="Error"):
36
  return f"""#### {title}
37
  {error}""" if error else ""
@@ -77,7 +99,7 @@ def auto_prompt_correction(prompt_ui,neg_prompt_ui,disable_auto_prompt_correctio
77
 
78
  if(prompt=="" and neg_prompt==""):
79
  prompt="anime, masterpiece, portrait, a girl with flowers, good pupil, 4k, detailed"
80
- neg_prompt=f"(((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
81
  return prompt, neg_prompt
82
 
83
  splited_prompt=prompt.replace(","," ").replace("_"," ").split(" ")
@@ -86,7 +108,7 @@ def auto_prompt_correction(prompt_ui,neg_prompt_ui,disable_auto_prompt_correctio
86
  for word in human_words:
87
  if( word in splited_prompt):
88
  prompt=f"anime, masterpiece, {prompt}, good pupil, 4k, detailed"
89
- neg_prompt=f"(((deformed))), blurry, ((((bad anatomy)))), {neg_prompt}, bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
90
  return prompt, neg_prompt
91
 
92
  animal_words=["cat","dog","bird"]
 
5
  from PIL import Image
6
  import random
7
  import os
8
+ from huggingface_hub import hf_hub_download
9
 
10
 
11
  model_id = 'aipicasso/picasso-diffusion-1-0-demo'
 
33
  pipe.enable_xformers_memory_efficient_attention()
34
  pipe_i2i.enable_xformers_memory_efficient_attention()
35
 
36
+ nfixer_path=hf_hub_download(repo_id=model_id, filename="nfixer.pt")
37
+ embeddings_dict=torch.load(nfixer_path)
38
+ print(embeddings_dict)
39
+ if "string_to_param" in embeddings_dict:
40
+ embeddings = next(iter(embeddings_dict['string_to_param'].values()))
41
+ placeholder_token = ""
42
+ for i, emb in enumerate(embeddings):
43
+ token = f"_s{i+1}"
44
+ placeholder_token += token
45
+ pipe.tokenizer.add_tokens(token)
46
+ pipe.text_encoder.resize_token_embeddings(len(pipe.tokenizer))
47
+ token_id = pipe.tokenizer.convert_tokens_to_ids(token)
48
+ pipe.text_encoder.get_input_embeddings().weight.data[token_id] = emb
49
+ else:
50
+ placeholder_token = list(embeddings_dict.keys())[0]
51
+ embeddings = embeddings_dict[placeholder_token].to(pipe.text_encoder.get_input_embeddings().weight.dtype)
52
+ pipe.tokenizer.add_tokens(placeholder_token)
53
+ pipe.text_encoder.resize_token_embeddings(len(pipe.tokenizer))
54
+ placeholder_token_id = pipe.tokenizer.convert_tokens_to_ids(placeholder_token)
55
+ pipe.text_encoder.get_input_embeddings().weight.data[placeholder_token_id] = embeddings
56
+
57
  def error_str(error, title="Error"):
58
  return f"""#### {title}
59
  {error}""" if error else ""
 
99
 
100
  if(prompt=="" and neg_prompt==""):
101
  prompt="anime, masterpiece, portrait, a girl with flowers, good pupil, 4k, detailed"
102
+ neg_prompt=f"{placeholder_token},(((deformed))), blurry, ((((bad anatomy)))), bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
103
  return prompt, neg_prompt
104
 
105
  splited_prompt=prompt.replace(","," ").replace("_"," ").split(" ")
 
108
  for word in human_words:
109
  if( word in splited_prompt):
110
  prompt=f"anime, masterpiece, {prompt}, good pupil, 4k, detailed"
111
+ neg_prompt=f"{placeholder_token},(((deformed))), blurry, ((((bad anatomy)))), {neg_prompt}, bad pupil, disfigured, poorly drawn face, mutation, mutated, (extra limb), (ugly), (poorly drawn hands), bad hands, fused fingers, messy drawing, broken legs censor, low quality, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), ((bad eyes)), ui, error, missing fingers, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, long body, uncoordinated body, unnatural body, lowres, jpeg artifacts, 3d, cg, text"
112
  return prompt, neg_prompt
113
 
114
  animal_words=["cat","dog","bird"]