Omnibus commited on
Commit
42c5e66
·
verified ·
1 Parent(s): 9890778

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -5,7 +5,11 @@ import requests
5
  import uuid
6
  import io
7
  import base64
8
- import threading
 
 
 
 
9
 
10
  loaded_model=[]
11
  for i,model in enumerate(models):
@@ -16,7 +20,33 @@ for i,model in enumerate(models):
16
  pass
17
  print (loaded_model)
18
 
 
19
  def run_dif(out_prompt,model_drop,cnt):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  p_seed=""
21
  out_box=[]
22
  out_html=""
 
5
  import uuid
6
  import io
7
  import base64
8
+
9
+ import torch
10
+ from diffusers import AutoPipelineForImage2Image
11
+ from diffusers.utils import make_image_grid, load_image
12
+
13
 
14
  loaded_model=[]
15
  for i,model in enumerate(models):
 
20
  pass
21
  print (loaded_model)
22
 
23
+
24
  def run_dif(out_prompt,model_drop,cnt):
25
+ out_box=[]
26
+
27
+ pipeline = AutoPipelineForImage2Image.from_pretrained(
28
+ "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
29
+ )
30
+ pipeline.enable_model_cpu_offload()
31
+ # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
32
+ pipeline.enable_xformers_memory_efficient_attention()
33
+
34
+ # prepare image
35
+ url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png"
36
+ init_image = load_image(url)
37
+
38
+ prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
39
+
40
+ # pass prompt and image to pipeline
41
+ image = pipeline(prompt, image=init_image, strength=0.8).images[0]
42
+ #make_image_grid([init_image, image], rows=1, cols=2)
43
+ out_box.append(image)
44
+ return out_box,""
45
+
46
+
47
+
48
+
49
+ def run_dif_old(out_prompt,model_drop,cnt):
50
  p_seed=""
51
  out_box=[]
52
  out_html=""