woods-today commited on
Commit
4da3b9a
1 Parent(s): 640e81f

Working on it

Browse files
routers/__pycache__/training.cpython-311.pyc CHANGED
Binary files a/routers/__pycache__/training.cpython-311.pyc and b/routers/__pycache__/training.cpython-311.pyc differ
 
routers/training.py CHANGED
@@ -10,9 +10,13 @@ from io import BytesIO
10
  from pydantic import BaseModel
11
  import base64
12
  import uuid
 
13
 
14
  from diffusers import StableDiffusionImg2ImgPipeline
15
 
 
 
 
16
  model_id_or_path = "runwayml/stable-diffusion-v1-5"
17
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
18
  pipe = pipe.to("cuda")
@@ -31,6 +35,10 @@ class ActionBody(BaseModel):
31
  @router.post("/perform-action")
32
  async def performAction(actionBody: ActionBody):
33
 
 
 
 
 
34
  response = requests.get(actionBody.url)
35
  init_image = Image.open(BytesIO(response.content)).convert("RGB")
36
  init_image = init_image.resize((actionBody.resizeW, actionBody.resizeH))
@@ -42,9 +50,12 @@ async def performAction(actionBody: ActionBody):
42
  imgUUID = str(uuid.uuid4())
43
  images[0].save(imgUUID+".png")
44
 
 
 
45
  return {
46
  "imageName" : imgUUID+".png",
47
- "image": "data:image/jpeg;base64,"+str(img_str)
 
48
  }
49
 
50
 
@@ -67,5 +78,5 @@ async def hifunction():
67
  # images[0].save("fantasy_landscape.png")
68
 
69
  return {
70
- "image": "data:image/jpeg;base64,"+str(img_str)
71
  }
 
10
  from pydantic import BaseModel
11
  import base64
12
  import uuid
13
+ from transformers import AutoTokenizer
14
 
15
  from diffusers import StableDiffusionImg2ImgPipeline
16
 
17
+ tokenizer = AutoTokenizer.from_pretrained("openlm-research/open_llama_7b")
18
+
19
+
20
  model_id_or_path = "runwayml/stable-diffusion-v1-5"
21
  pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
22
  pipe = pipe.to("cuda")
 
35
  @router.post("/perform-action")
36
  async def performAction(actionBody: ActionBody):
37
 
38
+ model_inputs = tokenizer(["A list of colors: red, blue"], return_tensors="pt").to("cuda")
39
+ generated_ids = model.generate(**model_inputs)
40
+ output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
41
+
42
  response = requests.get(actionBody.url)
43
  init_image = Image.open(BytesIO(response.content)).convert("RGB")
44
  init_image = init_image.resize((actionBody.resizeW, actionBody.resizeH))
 
50
  imgUUID = str(uuid.uuid4())
51
  images[0].save(imgUUID+".png")
52
 
53
+
54
+
55
  return {
56
  "imageName" : imgUUID+".png",
57
+ "image": "data:image/jpeg;base64,"+img_str.decode(),
58
+ "output": output
59
  }
60
 
61
 
 
78
  # images[0].save("fantasy_landscape.png")
79
 
80
  return {
81
+ "image": "data:image/jpeg;base64,"+img_str.decode()
82
  }