Yaron Koresh commited on
Commit
38d67a2
·
verified ·
1 Parent(s): 3d97621

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -45
app.py CHANGED
@@ -17,27 +17,16 @@ from torch.multiprocessing import Pool as Pool
17
  #from diffusers.utils import export_to_gif
18
  #from huggingface_hub import hf_hub_download
19
  #from safetensors.torch import load_file
20
- from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline
21
  from diffusers.utils import load_image
22
  #import jax
23
  #import jax.numpy as jnp
24
 
25
- def port_inc():
26
- env = os.getenv("CUSTOM_PORT")
27
- if env == None:
28
- os.environ["CUSTOM_PORT"]="7860"
29
- else:
30
- os.environ["CUSTOM_PORT"]=str(int(env)+1)
31
-
32
  def pipe_t2i():
33
  PIPE = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16, token=os.getenv("hf_token")).to("cuda")
34
- return PIPE
35
-
36
- def pipe_i2i():
37
- PIPE = DiffusionPipeline.from_pretrained("yisol/IDM-VTON", torch_dtype=torch.float16).to("cuda")
38
  PIPE.unet = torch.compile(PIPE.unet, mode="reduce-overhead", fullgraph=True)
39
  return PIPE
40
-
41
  def translate(text,lang):
42
  if text == None or lang == None:
43
  return ""
@@ -84,7 +73,7 @@ def generate_random_string(length):
84
  return ''.join(random.choice(characters) for _ in range(length))
85
 
86
  @spaces.GPU(duration=75)
87
- def Piper(name,name2,posi,neg):
88
  print("starting piper")
89
 
90
  ret1 = pp1(
@@ -96,15 +85,6 @@ def Piper(name,name2,posi,neg):
96
  guidance_scale=0
97
  )
98
  ret1.images[0].save(name)
99
-
100
- img = load_image(name).convert("RGB")
101
-
102
- ret2 = pp2(
103
- prompt=posi,
104
- negative_prompt=neg,
105
- image=img
106
- )
107
- ret2.images[0].save(name2)
108
 
109
  def tok(pipe,txt):
110
  toks = pipe.tokenizer(txt)['input_ids']
@@ -154,28 +134,21 @@ def infer(p):
154
  print("infer: started")
155
 
156
  p1 = p["a"]
157
- p2 = p["b"]
158
  name = generate_random_string(12)+".png"
159
- name2 = "_"+name
160
 
161
  _do = ['beautiful', 'playful', 'photographed', 'realistic', 'dynamic poze', 'deep field', 'reasonable coloring', 'rough texture', 'best quality', 'focused']
162
  if p1 != "":
163
  _do.append(f'{p1}')
164
  posi = " ".join(_do)
165
 
166
- neg = " "
167
- if p2 != "":
168
- neg = f'{p2} where in {p1}'
169
-
170
- Piper(name,name2,posi,neg)
171
 
172
- return name2
173
 
174
- def run(p1,p2,*result):
175
 
176
  p1_en = translate(p1,"english")
177
- p2_en = translate(p2,"english")
178
- p = {"a":p1_en,"b":p2_en}
179
  ln = len(result)
180
  print("images: "+str(ln))
181
  rng = list(range(ln))
@@ -193,11 +166,9 @@ def main():
193
 
194
  global result
195
  global pp1
196
- global pp2
197
 
198
  result=[]
199
  pp1=pipe_t2i()
200
- pp2=pipe_i2i()
201
 
202
  mp.set_start_method("fork", force=True)
203
 
@@ -209,14 +180,7 @@ def main():
209
  with gr.Row():
210
  prompt = gr.Textbox(
211
  elem_id="prompt",
212
- placeholder="INCLUDE",
213
- container=False,
214
- max_lines=1
215
- )
216
- with gr.Row():
217
- prompt2 = gr.Textbox(
218
- elem_id="prompt2",
219
- placeholder="EXCLUDE",
220
  container=False,
221
  max_lines=1
222
  )
@@ -225,8 +189,9 @@ def main():
225
  with gr.Row():
226
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
227
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
 
228
 
229
- run_button.click(fn=run,inputs=[prompt,prompt2,*result],outputs=result)
230
  demo.queue().launch()
231
 
232
  if __name__ == "__main__":
 
17
  #from diffusers.utils import export_to_gif
18
  #from huggingface_hub import hf_hub_download
19
  #from safetensors.torch import load_file
20
+ from diffusers import DiffusionPipeline
21
  from diffusers.utils import load_image
22
  #import jax
23
  #import jax.numpy as jnp
24
 
 
 
 
 
 
 
 
25
  def pipe_t2i():
26
  PIPE = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16, token=os.getenv("hf_token")).to("cuda")
 
 
 
 
27
  PIPE.unet = torch.compile(PIPE.unet, mode="reduce-overhead", fullgraph=True)
28
  return PIPE
29
+
30
  def translate(text,lang):
31
  if text == None or lang == None:
32
  return ""
 
73
  return ''.join(random.choice(characters) for _ in range(length))
74
 
75
  @spaces.GPU(duration=75)
76
+ def Piper(name,posi):
77
  print("starting piper")
78
 
79
  ret1 = pp1(
 
85
  guidance_scale=0
86
  )
87
  ret1.images[0].save(name)
 
 
 
 
 
 
 
 
 
88
 
89
  def tok(pipe,txt):
90
  toks = pipe.tokenizer(txt)['input_ids']
 
134
  print("infer: started")
135
 
136
  p1 = p["a"]
 
137
  name = generate_random_string(12)+".png"
 
138
 
139
  _do = ['beautiful', 'playful', 'photographed', 'realistic', 'dynamic poze', 'deep field', 'reasonable coloring', 'rough texture', 'best quality', 'focused']
140
  if p1 != "":
141
  _do.append(f'{p1}')
142
  posi = " ".join(_do)
143
 
144
+ Piper(name,posi)
 
 
 
 
145
 
146
+ return name
147
 
148
+ def run(p1,*result):
149
 
150
  p1_en = translate(p1,"english")
151
+ p = {"a":p1_en}
 
152
  ln = len(result)
153
  print("images: "+str(ln))
154
  rng = list(range(ln))
 
166
 
167
  global result
168
  global pp1
 
169
 
170
  result=[]
171
  pp1=pipe_t2i()
 
172
 
173
  mp.set_start_method("fork", force=True)
174
 
 
180
  with gr.Row():
181
  prompt = gr.Textbox(
182
  elem_id="prompt",
183
+ placeholder="KEYWORDS",
 
 
 
 
 
 
 
184
  container=False,
185
  max_lines=1
186
  )
 
189
  with gr.Row():
190
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
191
  result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
192
+ result.append(gr.Image(interactive=False,elem_classes="image-container", label="Result", show_label=False, type='filepath', show_share_button=False))
193
 
194
+ run_button.click(fn=run,inputs=[prompt,*result],outputs=result)
195
  demo.queue().launch()
196
 
197
  if __name__ == "__main__":