woods-today commited on
Commit
e5727cb
·
1 Parent(s): 5948e4d

Workin on it

Browse files
Files changed (1) hide show
  1. routers/training.py +18 -2
routers/training.py CHANGED
@@ -13,14 +13,23 @@ import uuid
13
  from transformers import AutoTokenizer, AutoModelForCausalLM
14
 
15
  from diffusers import StableDiffusionImg2ImgPipeline
 
16
 
17
  # tokenizer = AutoTokenizer.from_pretrained("openlm-research/open_llama_7b")
18
  # model = AutoModelForCausalLM.from_pretrained(
19
  # "openlm-research/open_llama_7b", device_map="auto", load_in_4bit=True
20
  # )
21
 
22
- model_id_or_path = "runwayml/stable-diffusion-v1-5"
23
- pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
 
 
 
 
 
 
 
 
24
  pipe = pipe.to("cuda")
25
 
26
 
@@ -28,6 +37,7 @@ router = APIRouter()
28
 
29
  class ActionBody(BaseModel):
30
  url: str
 
31
  prompt: str
32
  strength: float
33
  guidance_scale: float
@@ -44,6 +54,12 @@ async def performAction(actionBody: ActionBody):
44
  response = requests.get(actionBody.url)
45
  init_image = Image.open(BytesIO(response.content)).convert("RGB")
46
  init_image = init_image.resize((actionBody.resizeW, actionBody.resizeH))
 
 
 
 
 
 
47
  images = pipe(prompt=actionBody.prompt, image=init_image, strength=actionBody.strength, guidance_scale=actionBody.guidance_scale).images
48
  print(images)
49
  buffered = BytesIO()
 
13
  from transformers import AutoTokenizer, AutoModelForCausalLM
14
 
15
  from diffusers import StableDiffusionImg2ImgPipeline
16
+ from diffusers import StableDiffusionInpaintPipeline
17
 
18
  # tokenizer = AutoTokenizer.from_pretrained("openlm-research/open_llama_7b")
19
  # model = AutoModelForCausalLM.from_pretrained(
20
  # "openlm-research/open_llama_7b", device_map="auto", load_in_4bit=True
21
  # )
22
 
23
+ # model_id_or_path = "runwayml/stable-diffusion-v1-5"
24
+ # pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
25
+
26
+
27
+ pipe = StableDiffusionInpaintPipeline.from_pretrained(
28
+ "runwayml/stable-diffusion-inpainting",
29
+ revision="fp16",
30
+ torch_dtype=torch.float16,
31
+ )
32
+
33
  pipe = pipe.to("cuda")
34
 
35
 
 
37
 
38
  class ActionBody(BaseModel):
39
  url: str
40
+ maskUrl: str
41
  prompt: str
42
  strength: float
43
  guidance_scale: float
 
54
  response = requests.get(actionBody.url)
55
  init_image = Image.open(BytesIO(response.content)).convert("RGB")
56
  init_image = init_image.resize((actionBody.resizeW, actionBody.resizeH))
57
+
58
+ response = requests.get(actionBody.maskUrl)
59
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
60
+ init_image = init_image.resize((actionBody.resizeW, actionBody.resizeH))
61
+
62
+
63
  images = pipe(prompt=actionBody.prompt, image=init_image, strength=actionBody.strength, guidance_scale=actionBody.guidance_scale).images
64
  print(images)
65
  buffered = BytesIO()