Using PAth for imports
Browse files- handler.py +30 -25
handler.py
CHANGED
|
@@ -6,6 +6,7 @@ from io import BytesIO
|
|
| 6 |
from pprint import pprint
|
| 7 |
from typing import Any, Dict, List
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
import torch
|
| 11 |
from diffusers import (
|
|
@@ -20,13 +21,10 @@ from torch import autocast
|
|
| 20 |
# https://huggingface.co/philschmid/stable-diffusion-v1-4-endpoints
|
| 21 |
# https://huggingface.co/docs/inference-endpoints/guides/custom_handler
|
| 22 |
|
|
|
|
| 23 |
|
| 24 |
# if local avoid repo url
|
| 25 |
-
|
| 26 |
-
PREFIX_URL = ""
|
| 27 |
-
if not LOCAL:
|
| 28 |
-
PREFIX_URL = "https://huggingface.co/isatis/kw/tree/main/"
|
| 29 |
-
|
| 30 |
|
| 31 |
# set device
|
| 32 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
@@ -36,46 +34,53 @@ if device.type != "cuda":
|
|
| 36 |
|
| 37 |
|
| 38 |
class EndpointHandler:
|
| 39 |
-
print(os.getcwd())
|
| 40 |
-
|
| 41 |
LORA_PATHS = {
|
| 42 |
-
"hairdetailer":
|
| 43 |
-
"lora_leica":
|
| 44 |
-
"epiNoiseoffset_v2":
|
| 45 |
-
"MBHU-TT2FRS":
|
| 46 |
-
"ShinyOiledSkin_v20":
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
"
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
TEXTUAL_INVERSION = [
|
| 55 |
{
|
| 56 |
-
"weight_name":
|
| 57 |
"token": "easynegative",
|
| 58 |
},
|
| 59 |
{
|
| 60 |
-
"weight_name":
|
| 61 |
"token": "EasyNegative",
|
| 62 |
},
|
| 63 |
-
{"weight_name": PREFIX_URL + "embeddings/badhandv4.pt", "token": "badhandv4"},
|
| 64 |
{
|
| 65 |
-
"weight_name":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
"token": "bad-artist-anime",
|
| 67 |
},
|
| 68 |
-
{"weight_name": PREFIX_URL + "embeddings/NegfeetV2.pt", "token": "NegfeetV2"},
|
| 69 |
{
|
| 70 |
-
"weight_name":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
"token": "ng_deepnegative_v1_75t",
|
| 72 |
},
|
| 73 |
{
|
| 74 |
-
"weight_name":
|
| 75 |
"token": "NG_DeepNegative_V1_75T",
|
| 76 |
},
|
| 77 |
{
|
| 78 |
-
"weight_name":
|
| 79 |
"token": "bad-hands-5",
|
| 80 |
},
|
| 81 |
]
|
|
|
|
| 6 |
from pprint import pprint
|
| 7 |
from typing import Any, Dict, List
|
| 8 |
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
|
| 11 |
import torch
|
| 12 |
from diffusers import (
|
|
|
|
| 21 |
# https://huggingface.co/philschmid/stable-diffusion-v1-4-endpoints
|
| 22 |
# https://huggingface.co/docs/inference-endpoints/guides/custom_handler
|
| 23 |
|
| 24 |
+
REPO_DIR = Path(__file__).resolve().parent
|
| 25 |
|
| 26 |
# if local avoid repo url
|
| 27 |
+
print(os.getcwd())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# set device
|
| 30 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
class EndpointHandler:
|
|
|
|
|
|
|
| 37 |
LORA_PATHS = {
|
| 38 |
+
"hairdetailer": str(REPO_DIR / "lora/hairdetailer.safetensors"),
|
| 39 |
+
"lora_leica": str(REPO_DIR / "lora/lora_leica.safetensors"),
|
| 40 |
+
"epiNoiseoffset_v2": str(REPO_DIR / "lora/epiNoiseoffset_v2.safetensors"),
|
| 41 |
+
"MBHU-TT2FRS": str(REPO_DIR / "lora/MBHU-TT2FRS.safetensors"),
|
| 42 |
+
"ShinyOiledSkin_v20": str(
|
| 43 |
+
REPO_DIR / "lora/ShinyOiledSkin_v20-LoRA.safetensors"
|
| 44 |
+
),
|
| 45 |
+
"polyhedron_new_skin_v1.1": str(
|
| 46 |
+
REPO_DIR / "lora/polyhedron_new_skin_v1.1.safetensors"
|
| 47 |
+
),
|
| 48 |
+
"detailed_eye-10": str(REPO_DIR / "lora/detailed_eye-10.safetensors"),
|
| 49 |
+
"add_detail": str(REPO_DIR / "lora/add_detail.safetensors"),
|
| 50 |
+
"MuscleGirl_v1": str(REPO_DIR / "lora/MuscleGirl_v1.safetensors"),
|
| 51 |
}
|
| 52 |
|
| 53 |
TEXTUAL_INVERSION = [
|
| 54 |
{
|
| 55 |
+
"weight_name": str(REPO_DIR / "embeddings/EasyNegative.safetensors"),
|
| 56 |
"token": "easynegative",
|
| 57 |
},
|
| 58 |
{
|
| 59 |
+
"weight_name": str(REPO_DIR / "embeddings/EasyNegative.safetensors"),
|
| 60 |
"token": "EasyNegative",
|
| 61 |
},
|
|
|
|
| 62 |
{
|
| 63 |
+
"weight_name": str(REPO_DIR / "embeddings/badhandv4.pt"),
|
| 64 |
+
"token": "badhandv4",
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"weight_name": str(REPO_DIR / "embeddings/bad-artist-anime.pt"),
|
| 68 |
"token": "bad-artist-anime",
|
| 69 |
},
|
|
|
|
| 70 |
{
|
| 71 |
+
"weight_name": str(REPO_DIR / "embeddings/NegfeetV2.pt"),
|
| 72 |
+
"token": "NegfeetV2",
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"weight_name": str(REPO_DIR / "embeddings/ng_deepnegative_v1_75t.pt"),
|
| 76 |
"token": "ng_deepnegative_v1_75t",
|
| 77 |
},
|
| 78 |
{
|
| 79 |
+
"weight_name": str(REPO_DIR / "embeddings/ng_deepnegative_v1_75t.pt"),
|
| 80 |
"token": "NG_DeepNegative_V1_75T",
|
| 81 |
},
|
| 82 |
{
|
| 83 |
+
"weight_name": str(REPO_DIR / "embeddings/bad-hands-5.pt"),
|
| 84 |
"token": "bad-hands-5",
|
| 85 |
},
|
| 86 |
]
|