KingNish commited on
Commit
4b27876
1 Parent(s): 9dabfc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -24,7 +24,6 @@ CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "1")
24
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "6000"))
25
  USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
26
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
27
- PORT = int(os.getenv("DEMO_PORT", "15432"))
28
 
29
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
30
 
@@ -88,6 +87,12 @@ STYLE_NAMES = list(styles.keys())
88
  DEFAULT_STYLE_NAME = "(No style)"
89
  NUM_IMAGES_PER_PROMPT = 1
90
 
 
 
 
 
 
 
91
  if torch.cuda.is_available():
92
 
93
  pipe = PixArtAlphaPipeline.from_pretrained(
@@ -141,7 +146,7 @@ def generate(
141
  generator = torch.Generator().manual_seed(seed)
142
 
143
  if not use_negative_prompt:
144
- negative_prompt = None # type: ignore
145
  prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
146
 
147
  images = pipe(
 
24
  MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "6000"))
25
  USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
26
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
 
27
 
28
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
29
 
 
87
  DEFAULT_STYLE_NAME = "(No style)"
88
  NUM_IMAGES_PER_PROMPT = 1
89
 
90
+ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
91
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
92
+ if not negative:
93
+ negative = ""
94
+ return p.replace("{prompt}", positive), n + negative
95
+
96
  if torch.cuda.is_available():
97
 
98
  pipe = PixArtAlphaPipeline.from_pretrained(
 
146
  generator = torch.Generator().manual_seed(seed)
147
 
148
  if not use_negative_prompt:
149
+ negative_prompt = None
150
  prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
151
 
152
  images = pipe(