UAI-Software commited on
Commit
48e53fd
1 Parent(s): 00211bf

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SDXL Flash
2
+
3
+ Process SDXL models with [SDXL Flash](https://huggingface.co/sd-community/sdxl-flash)
4
+
5
+ ## Request
6
+
7
+ JSON Request
8
+
9
+ ```java
10
+ {
11
+ inputs (:obj: `array` | [])
12
+ seed (:obj: `int`)
13
+ prompt (:obj: `str`)
14
+ negative_prompt (:obj: `str`)
15
+ num_images_per_prompt (:obj: `int`)
16
+ steps (:obj: `int`)
17
+ guidance_scale (:obj: `float`)
18
+ width (:obj: `int`)
19
+ height (:obj: `int`)
20
+ model (:obj: `str`, :default: `sd-community/sdxl-flash`)
21
+ }
22
+ ```
__pycache__/imageRequest.cpython-39.pyc ADDED
Binary file (10 kB). View file
 
__pycache__/my_handler.cpython-39.pyc ADDED
Binary file (1.46 kB). View file
 
deploy.bat ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+
2
+ set CURRENT_DIR=%CD%
3
+ set SCRIPT_DIR=%~dp0
4
+
5
+ cd %SCRIPT_DIR%
6
+
7
+ F:\Projects\UAI\UAIBrainServer\Code\Env\Scripts\huggingface-cli.exe upload API-SDXL-Flash . .
8
+
9
+ cd %CURRENT_DIR%
handler.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import Dict, List, Any
3
+ import sys
4
+ rootDir = os.path.abspath(os.path.dirname(__file__))
5
+ sys.path.append(rootDir)
6
+ from uaiDiffusers.common.imageRequest import ImageRequest
7
+ from diffusers import StableDiffusionXLPipeline, DPMSolverSinglestepScheduler
8
+ import torch
9
+ from uaiDiffusers.uaiDiffusers import ImagesToBase64
10
+
11
+ import torch
12
+
13
+ class EndpointHandler:
14
+ def __init__(self, path=""):
15
+ # Preload all the elements you are going to need at inference.
16
+ # pseudo:
17
+ # self.model= load_model(path)
18
+ self.pipe = None
19
+ self.modelName = ""
20
+ baseReq = ImageRequest()
21
+ baseReq.model = path
22
+ print(f"Loading model: {path}")
23
+ self.LoadModel(baseReq)
24
+
25
+ def LoadModel(self, request):
26
+ base = "sd-community/sdxl-flash"
27
+ if request.model == "default":
28
+ request.model = base
29
+ else:
30
+ base = request.model
31
+ if self.pipe is None:
32
+ del self.pipe
33
+ torch.cuda.empty_cache()
34
+ self.pipe = StableDiffusionXLPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to("cuda")
35
+
36
+ # Ensure sampler uses "trailing" timesteps.
37
+ self.pipe.scheduler = DPMSolverSinglestepScheduler.from_config(self.pipe.scheduler.config, timestep_spacing="trailing")
38
+
39
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
40
+ """
41
+ data args:
42
+ input (:obj: `str` | `PIL.Image` | `np.array`)
43
+ seed (:obj: `int`)
44
+ prompt (:obj: `str`)
45
+ negative_prompt (:obj: `str`)
46
+ num_images_per_prompt (:obj: `int`)
47
+ steps (:obj: `int`)
48
+ guidance_scale (:obj: `float`)
49
+ width (:obj: `int`)
50
+ height (:obj: `int`)
51
+
52
+ kwargs
53
+ Return:
54
+ A :obj:`list` | `dict`: will be serialized and returned
55
+ """
56
+ # inputs = data.pop("parameters", data)
57
+ request = ImageRequest.FromDict(data)
58
+ response = self.__runProcess__(request)
59
+ return response
60
+
61
+ def __runProcess__(self, request: ImageRequest) -> List[Dict[str, Any]]:
62
+ """
63
+ Run SDXL Lightning pipeline
64
+ """
65
+
66
+ self.LoadModel(request)
67
+
68
+ # Ensure using the same inference steps as the loaded model and CFG set to 0.
69
+ images = self.pipe(request.prompt, negative_prompt = request.negative_prompt, num_inference_steps=request.steps, guidance_scale=request.guidance_scale, num_images_per_prompt=request.num_images_per_prompt ).images
70
+
71
+ return {"media":[{"media":ImagesToBase64(img)} for img in images]}
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ uaiDiffusers