VikramSingh178 commited on
Commit
f1b2ef2
1 Parent(s): f5695c0

Add new endpoints for product diffusion API and SDXL-LoRA inference

Browse files
product_diffusion_api/__init__.py ADDED
File without changes
product_diffusion_api/endpoints.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+
4
+
5
+
6
+
7
+ app = FastAPI(openapi_url='/api/v1/product-diffusion/openapi.json',docs_url='/api/v1/product_diffusion/docs')
8
+ app.add_middleware(
9
+ CORSMiddleware,
10
+ allow_origins = ["*"],
11
+ allow_methods = ["*"],
12
+ allow_headers=["*"],
13
+ allow_credentials = True
14
+
15
+ )
16
+
17
+ app.include_router(sdxl_text_to_image.router, prefix='/api/v1/product-diffusion')
18
+ app.include_router()
19
+
20
+
21
+ @app.get('/')
22
+ async def root():
23
+ return {'message: Product Diffusion API'}
scripts/sdxl_lora_inference.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from wandb.integration.diffusers import autolog
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
+ from config import PROJECT_NAME
5
+ autolog(init=dict(project=PROJECT_NAME))
6
+
7
+ class SDXLLoraInference:
8
+ """
9
+ Class for running inference using the SDXL-LoRA model to generate stunning product photographs.
10
+
11
+ Args:
12
+ num_inference_steps (int): The number of inference steps to perform.
13
+ guidance_scale (float): The scale factor for guidance during inference.
14
+ """
15
+ def __init__(self, num_inference_steps: int, guidance_scale: float) -> None:
16
+ self.model_path = "VikramSingh178/sdxl-lora-finetune-product-caption"
17
+ self.pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
18
+ self.pipe.to("cuda")
19
+ self.pipe.load_lora_weights(self.model_path)
20
+ self.num_inference_steps = num_inference_steps
21
+ self.guidance_scale = guidance_scale
22
+
23
+ def run_inference(self, prompt):
24
+ """
25
+ Runs inference using the SDXL-LoRA model to generate a stunning product photograph.
26
+
27
+ Args:
28
+ prompt: The input prompt for generating the product photograph.
29
+
30
+ Returns:
31
+ images: The generated product photograph(s).
32
+ """
33
+
34
+ prompt = prompt
35
+ images = self.pipe(prompt, num_inference_steps=self.num_inference_steps, guidance_scale=self.guidance_scale).images
36
+ return images
37
+
38
+ inference = SDXLLoraInference(num_inference_steps=100, guidance_scale=2.5)
39
+ inference.run_inference(prompt= "A stunning 4k Shot of a Balenciaga X Anime Hoodie with a person wearing it in a party" )
scripts/wandb/debug-internal.log CHANGED
@@ -1 +1 @@
1
- run-20240429_145519-r0eclldx/logs/debug-internal.log
 
1
+ run-20240430_104236-lcgqwfyr/logs/debug-internal.log
scripts/wandb/debug.log CHANGED
@@ -1 +1 @@
1
- run-20240429_145519-r0eclldx/logs/debug.log
 
1
+ run-20240430_104236-lcgqwfyr/logs/debug.log
scripts/wandb/latest-run CHANGED
@@ -1 +1 @@
1
- run-20240429_145519-r0eclldx
 
1
+ run-20240430_104236-lcgqwfyr