VikramSingh178 commited on
Commit
7b86905
1 Parent(s): d68b387

refactor: Update logfire configuration in product diffusion API

Browse files
product_diffusion_api/__pycache__/endpoints.cpython-310.pyc CHANGED
Binary files a/product_diffusion_api/__pycache__/endpoints.cpython-310.pyc and b/product_diffusion_api/__pycache__/endpoints.cpython-310.pyc differ
 
product_diffusion_api/__pycache__/utils.cpython-310.pyc ADDED
Binary file (387 Bytes). View file
 
product_diffusion_api/endpoints.py CHANGED
@@ -2,9 +2,11 @@ from fastapi import FastAPI
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from routers import sdxl_text_to_image
4
  from routers import painting
5
-
6
  import logfire
7
 
 
 
 
8
  logfire.configure(pydantic_plugin=logfire.PydanticPlugin(record='all'))
9
 
10
 
 
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from routers import sdxl_text_to_image
4
  from routers import painting
 
5
  import logfire
6
 
7
+
8
+
9
+
10
  logfire.configure(pydantic_plugin=logfire.PydanticPlugin(record='all'))
11
 
12
 
product_diffusion_api/routers/__pycache__/sdxl_text_to_image.cpython-310.pyc CHANGED
Binary files a/product_diffusion_api/routers/__pycache__/sdxl_text_to_image.cpython-310.pyc and b/product_diffusion_api/routers/__pycache__/sdxl_text_to_image.cpython-310.pyc differ
 
product_diffusion_api/routers/sdxl_text_to_image.py CHANGED
@@ -30,6 +30,16 @@ router = APIRouter()
30
 
31
 
32
  def pil_to_b64_json(image):
 
 
 
 
 
 
 
 
 
 
33
  image_id = str(uuid.uuid4())
34
  buffered = BytesIO()
35
  image.save(buffered, format="PNG")
@@ -37,7 +47,18 @@ def pil_to_b64_json(image):
37
  return {"image_id": image_id, "b64_image": b64_image}
38
 
39
 
40
- def pil_to_s3_json(image: Image.Image,file_name) -> str:
 
 
 
 
 
 
 
 
 
 
 
41
  image_id = str(uuid.uuid4())
42
  s3_uploader = S3ManagerService()
43
  image_bytes = io.BytesIO()
@@ -53,20 +74,29 @@ def pil_to_s3_json(image: Image.Image,file_name) -> str:
53
 
54
 
55
  @lru_cache(maxsize=1)
56
- def load_pipeline(model_name, adapter_name,adapter_name_2):
57
- pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype= torch.bfloat16 ).to(device)
 
 
 
 
 
 
 
 
 
 
58
  pipe.load_lora_weights(adapter_name)
59
- pipe.load_lora_weights(adapter_name_2)
60
- pipe.set_adapters([adapter_name, adapter_name_2], adapter_weights=[0.7, 0.5])
61
  pipe.fuse_lora()
62
  pipe.unload_lora_weights()
63
  pipe.unet.to(memory_format=torch.channels_last)
64
- #pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead")
 
65
  pipe.fuse_qkv_projections()
66
  return pipe
67
 
68
 
69
- loaded_pipeline = load_pipeline(config.MODEL_NAME, config.ADAPTER_NAME,config.ADAPTER_NAME_2)
70
 
71
 
72
  # SDXLLoraInference class for running inference
 
30
 
31
 
32
  def pil_to_b64_json(image):
33
+ """
34
+ Converts a PIL image to a base64-encoded JSON object.
35
+
36
+ Args:
37
+ image (PIL.Image.Image): The PIL image object to be converted.
38
+
39
+ Returns:
40
+ dict: A dictionary containing the image ID and the base64-encoded image.
41
+
42
+ """
43
  image_id = str(uuid.uuid4())
44
  buffered = BytesIO()
45
  image.save(buffered, format="PNG")
 
47
  return {"image_id": image_id, "b64_image": b64_image}
48
 
49
 
50
+ def pil_to_s3_json(image: Image.Image, file_name) -> str:
51
+ """
52
+ Uploads a PIL image to Amazon S3 and returns a JSON object containing the image ID and the signed URL.
53
+
54
+ Args:
55
+ image (PIL.Image.Image): The PIL image to be uploaded.
56
+ file_name (str): The name of the file.
57
+
58
+ Returns:
59
+ dict: A JSON object containing the image ID and the signed URL.
60
+
61
+ """
62
  image_id = str(uuid.uuid4())
63
  s3_uploader = S3ManagerService()
64
  image_bytes = io.BytesIO()
 
74
 
75
 
76
  @lru_cache(maxsize=1)
77
+ def load_pipeline(model_name, adapter_name):
78
+ """
79
+ Load the diffusion pipeline with the specified model and adapter names.
80
+
81
+ Args:
82
+ model_name (str): The name of the pretrained model.
83
+ adapter_name (str): The name of the adapter.
84
+
85
+ Returns:
86
+ DiffusionPipeline: The loaded diffusion pipeline.
87
+ """
88
+ pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch.bfloat16).to(device)
89
  pipe.load_lora_weights(adapter_name)
 
 
90
  pipe.fuse_lora()
91
  pipe.unload_lora_weights()
92
  pipe.unet.to(memory_format=torch.channels_last)
93
+ pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead")
94
+ pipe.vae.decode = torch.compile(pipe.vae.decode, mode="reduce-overhead")
95
  pipe.fuse_qkv_projections()
96
  return pipe
97
 
98
 
99
+ loaded_pipeline = load_pipeline(config.MODEL_NAME, config.ADAPTER_NAME)
100
 
101
 
102
  # SDXLLoraInference class for running inference
product_diffusion_api/{routers/utils.py → utils.py} RENAMED
File without changes