VikramSingh178 commited on
Commit
0695699
1 Parent(s): 080c0ac

chore: Update dependencies in requirements.txt and fix import statement in painting.py

Browse files

Former-commit-id: 4655fd747d81318b35f11a66885e8c4e5ce78e8b [formerly 076e97d0b56f534dc5908d0998b7e195c94f8f8a]
Former-commit-id: d6f4bb04acf087d0c30c84af9c3e0b8f9903becd

api/endpoints.py CHANGED
@@ -52,4 +52,4 @@ def check_health():
52
 
53
 
54
 
55
- #uvicorn.run(app, host='127.0.0.1', port=8000)
 
52
 
53
 
54
 
55
+ uvicorn.run(app, host='127.0.0.1', port=8000)
api/requirements.txt CHANGED
@@ -1,12 +1,12 @@
 
1
  config==0.5.1
2
  diffusers==0.27.2
3
  fastapi==0.111.0
4
  hydra-core==1.3.2
5
  lightning==2.2.3
6
- logfire==0.41.0
7
  Pillow==10.3.0
8
- pydantic==2.7.3
9
  torch==2.2.0
10
  utils==1.0.2
11
  uvicorn==0.30.1
12
-
 
1
+ async_batcher==0.2.0
2
  config==0.5.1
3
  diffusers==0.27.2
4
  fastapi==0.111.0
5
  hydra-core==1.3.2
6
  lightning==2.2.3
7
+ logfire==0.42.0
8
  Pillow==10.3.0
9
+ pydantic==2.7.4
10
  torch==2.2.0
11
  utils==1.0.2
12
  uvicorn==0.30.1
 
api/routers/painting.py CHANGED
@@ -2,7 +2,7 @@ import sys
2
  sys.path.append('../scripts')
3
  import os
4
  import uuid
5
- from typing import List, Tuple, Any,Dict
6
  from fastapi import APIRouter, File, UploadFile, HTTPException, Form, Depends, Body
7
  from pydantic import BaseModel, Field
8
  from PIL import Image
@@ -11,9 +11,7 @@ from utils import pil_to_s3_json, pil_to_b64_json, ImageAugmentation, accelerato
11
  from inpainting_pipeline import AutoPaintingPipeline, load_pipeline
12
  from hydra import compose, initialize
13
  from async_batcher.batcher import AsyncBatcher
14
- from concurrent.futures import Executor
15
  import json
16
- import asyncio
17
  from functools import lru_cache
18
 
19
  pl.seed_everything(42)
@@ -26,11 +24,20 @@ with initialize(version_base=None, config_path="../../configs"):
26
  # Load the inpainting pipeline
27
  @lru_cache(maxsize=1)
28
  def load_pipeline_wrapper():
 
 
 
 
 
 
29
  pipeline = load_pipeline(cfg.model, accelerator(), enable_compile=True)
30
  return pipeline
31
  inpainting_pipeline = load_pipeline_wrapper()
32
 
33
  class InpaintingRequest(BaseModel):
 
 
 
34
  prompt: str = Field(..., description="Prompt text for inference")
35
  negative_prompt: str = Field(..., description="Negative prompt text for inference")
36
  num_inference_steps: int = Field(..., description="Number of inference steps")
@@ -41,6 +48,9 @@ class InpaintingRequest(BaseModel):
41
  use_augmentation: bool = Field(True, description="Whether to use image augmentation")
42
 
43
  class InpaintingBatchRequestModel(BaseModel):
 
 
 
44
  requests: List[InpaintingRequest]
45
 
46
  async def save_image(image: UploadFile) -> str:
@@ -105,7 +115,7 @@ def run_inference(cfg, image_path: str, request: InpaintingRequest):
105
  cfg['detection_model'])
106
  else:
107
  image = Image.open(image_path)
108
- mask_image = None # Assume mask_image is provided or generated separately
109
 
110
  painting_pipeline = AutoPaintingPipeline(
111
  pipeline=inpainting_pipeline,
@@ -118,16 +128,26 @@ def run_inference(cfg, image_path: str, request: InpaintingRequest):
118
  negative_prompt=request.negative_prompt,
119
  num_inference_steps=request.num_inference_steps,
120
  strength=request.strength,
121
- guidance_scale=request.guidance_scale)
 
122
  if request.mode == "s3_json":
123
  return pil_to_s3_json(output, file_name="output.png")
124
  elif request.mode == "b64_json":
125
  return pil_to_b64_json(output)
126
  else:
127
  raise ValueError("Invalid mode. Supported modes are 'b64_json' and 's3_json'.")
128
-
129
  class InpaintingBatcher(AsyncBatcher):
130
  async def process_batch(self, batch: Tuple[List[str], List[InpaintingRequest]]) -> List[Dict[str, Any]]:
 
 
 
 
 
 
 
 
 
131
  image_paths, requests = batch
132
  results = []
133
  for image_path, request in zip(image_paths, requests):
@@ -190,7 +210,7 @@ async def inpainting_batch_inference(
190
 
191
  batcher = InpaintingBatcher(max_batch_size=64)
192
  image_paths = [await save_image(image) for image in images]
193
- results = await batcher.process_batch((image_paths, requests))
194
 
195
  return results
196
  except Exception as e:
 
2
  sys.path.append('../scripts')
3
  import os
4
  import uuid
5
+ from typing import List, Tuple, Any, Dict
6
  from fastapi import APIRouter, File, UploadFile, HTTPException, Form, Depends, Body
7
  from pydantic import BaseModel, Field
8
  from PIL import Image
 
11
  from inpainting_pipeline import AutoPaintingPipeline, load_pipeline
12
  from hydra import compose, initialize
13
  from async_batcher.batcher import AsyncBatcher
 
14
  import json
 
15
  from functools import lru_cache
16
 
17
  pl.seed_everything(42)
 
24
  # Load the inpainting pipeline
25
  @lru_cache(maxsize=1)
26
  def load_pipeline_wrapper():
27
+ """
28
+ Load the inpainting pipeline with the specified configuration.
29
+
30
+ Returns:
31
+ pipeline: The loaded inpainting pipeline.
32
+ """
33
  pipeline = load_pipeline(cfg.model, accelerator(), enable_compile=True)
34
  return pipeline
35
  inpainting_pipeline = load_pipeline_wrapper()
36
 
37
  class InpaintingRequest(BaseModel):
38
+ """
39
+ Model representing a request for inpainting inference.
40
+ """
41
  prompt: str = Field(..., description="Prompt text for inference")
42
  negative_prompt: str = Field(..., description="Negative prompt text for inference")
43
  num_inference_steps: int = Field(..., description="Number of inference steps")
 
48
  use_augmentation: bool = Field(True, description="Whether to use image augmentation")
49
 
50
  class InpaintingBatchRequestModel(BaseModel):
51
+ """
52
+ Model representing a batch request for inpainting inference.
53
+ """
54
  requests: List[InpaintingRequest]
55
 
56
  async def save_image(image: UploadFile) -> str:
 
115
  cfg['detection_model'])
116
  else:
117
  image = Image.open(image_path)
118
+ mask_image = None
119
 
120
  painting_pipeline = AutoPaintingPipeline(
121
  pipeline=inpainting_pipeline,
 
128
  negative_prompt=request.negative_prompt,
129
  num_inference_steps=request.num_inference_steps,
130
  strength=request.strength,
131
+ guidance_scale=request.guidance_scale,
132
+ num_images=request.num_images)
133
  if request.mode == "s3_json":
134
  return pil_to_s3_json(output, file_name="output.png")
135
  elif request.mode == "b64_json":
136
  return pil_to_b64_json(output)
137
  else:
138
  raise ValueError("Invalid mode. Supported modes are 'b64_json' and 's3_json'.")
139
+
140
  class InpaintingBatcher(AsyncBatcher):
141
  async def process_batch(self, batch: Tuple[List[str], List[InpaintingRequest]]) -> List[Dict[str, Any]]:
142
+ """
143
+ Process a batch of images and requests for inpainting inference.
144
+
145
+ Args:
146
+ batch (Tuple[List[str], List[InpaintingRequest]]): Tuple of image paths and corresponding requests.
147
+
148
+ Returns:
149
+ List[Dict[str, Any]]: List of resulting images in the specified mode ('b64_json' or 's3_json').
150
+ """
151
  image_paths, requests = batch
152
  results = []
153
  for image_path, request in zip(image_paths, requests):
 
210
 
211
  batcher = InpaintingBatcher(max_batch_size=64)
212
  image_paths = [await save_image(image) for image in images]
213
+ results = batcher.process_batch((image_paths, requests))
214
 
215
  return results
216
  except Exception as e:
api/routers/sdxl_text_to_image.py CHANGED
@@ -184,7 +184,7 @@ async def sdxl_v0_lora_inference(data: InputFormat):
184
  async def sdxl_v0_lora_inference_batch(data: List[InputFormat]):
185
  batcher = SDXLLoraBatcher(max_batch_size=-1)
186
  try:
187
- predictions = await batcher.process_batch(data)
188
  return predictions
189
  except Exception as e:
190
  print(f"Error in /sdxl_v0_lora_inference/batch: {e}")
 
184
  async def sdxl_v0_lora_inference_batch(data: List[InputFormat]):
185
  batcher = SDXLLoraBatcher(max_batch_size=-1)
186
  try:
187
+ predictions = batcher.process_batch(data)
188
  return predictions
189
  except Exception as e:
190
  print(f"Error in /sdxl_v0_lora_inference/batch: {e}")
scripts/inpainting_pipeline.py CHANGED
@@ -24,7 +24,7 @@ class AutoPaintingPipeline:
24
  self.target_width = target_width
25
  self.target_height = target_height
26
 
27
- def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float):
28
  output = self.pipeline(
29
  prompt=prompt,
30
  negative_prompt=negative_prompt,
@@ -33,6 +33,7 @@ class AutoPaintingPipeline:
33
  num_inference_steps=num_inference_steps,
34
  strength=strength,
35
  guidance_scale=guidance_scale,
 
36
  height=self.target_height,
37
  width=self.target_width
38
 
 
24
  self.target_width = target_width
25
  self.target_height = target_height
26
 
27
+ def run_inference(self, prompt: str, negative_prompt: str, num_inference_steps: int, strength: float, guidance_scale: float,num_images):
28
  output = self.pipeline(
29
  prompt=prompt,
30
  negative_prompt=negative_prompt,
 
33
  num_inference_steps=num_inference_steps,
34
  strength=strength,
35
  guidance_scale=guidance_scale,
36
+ num_images_per_prompt = num_images,
37
  height=self.target_height,
38
  width=self.target_width
39