zhiweili
commited on
Commit
·
c415a01
1
Parent(s):
f2cb7ad
add app_makeup
Browse files- app.py +3 -3
- app_makeup.py +6 -5
- inversion_run_adapter.py +7 -30
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from app_base import create_demo as create_demo_face
|
| 4 |
-
|
| 5 |
|
| 6 |
with gr.Blocks(css="style.css") as demo:
|
| 7 |
with gr.Tabs():
|
| 8 |
with gr.Tab(label="Face"):
|
| 9 |
create_demo_face()
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from app_base import create_demo as create_demo_face
|
| 4 |
+
from app_makeup import create_demo as create_demo_makeup
|
| 5 |
|
| 6 |
with gr.Blocks(css="style.css") as demo:
|
| 7 |
with gr.Tabs():
|
| 8 |
with gr.Tab(label="Face"):
|
| 9 |
create_demo_face()
|
| 10 |
+
with gr.Tab(label="Makeup"):
|
| 11 |
+
create_demo_makeup()
|
| 12 |
|
| 13 |
demo.launch()
|
app_makeup.py
CHANGED
|
@@ -35,6 +35,7 @@ def create_demo() -> gr.Blocks:
|
|
| 35 |
w2 = 1.0
|
| 36 |
|
| 37 |
input_image = Image.open(input_image_path)
|
|
|
|
| 38 |
|
| 39 |
w2 = 1.0
|
| 40 |
run_model = adapter_run
|
|
@@ -59,17 +60,17 @@ def create_demo() -> gr.Blocks:
|
|
| 59 |
tmpPrefix = "/tmp/gradio/"
|
| 60 |
|
| 61 |
extension = 'png'
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
targetDir = f"{tmpPrefix}output/"
|
| 68 |
if not os.path.exists(targetDir):
|
| 69 |
os.makedirs(targetDir)
|
| 70 |
|
| 71 |
enhanced_path = f"{targetDir}{uuid.uuid4()}.{extension}"
|
| 72 |
-
enhanced_image.save(enhanced_path, quality=100)
|
| 73 |
|
| 74 |
return enhanced_path
|
| 75 |
|
|
|
|
| 35 |
w2 = 1.0
|
| 36 |
|
| 37 |
input_image = Image.open(input_image_path)
|
| 38 |
+
icc_profile = input_image.info.get("icc_profile")
|
| 39 |
|
| 40 |
w2 = 1.0
|
| 41 |
run_model = adapter_run
|
|
|
|
| 60 |
tmpPrefix = "/tmp/gradio/"
|
| 61 |
|
| 62 |
extension = 'png'
|
| 63 |
+
if enhanced_image.mode == 'RGBA':
|
| 64 |
+
extension = 'png'
|
| 65 |
+
else:
|
| 66 |
+
extension = 'jpg'
|
| 67 |
|
| 68 |
targetDir = f"{tmpPrefix}output/"
|
| 69 |
if not os.path.exists(targetDir):
|
| 70 |
os.makedirs(targetDir)
|
| 71 |
|
| 72 |
enhanced_path = f"{targetDir}{uuid.uuid4()}.{extension}"
|
| 73 |
+
enhanced_image.save(enhanced_path, quality=100, icc_profile=icc_profile)
|
| 74 |
|
| 75 |
return enhanced_path
|
| 76 |
|
inversion_run_adapter.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
|
| 3 |
from diffusers import (
|
| 4 |
DDPMScheduler,
|
|
@@ -17,35 +18,12 @@ from config import get_config, get_num_steps_actual
|
|
| 17 |
from functools import partial
|
| 18 |
from compel import Compel, ReturnedEmbeddingsType
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
args = Object()
|
| 24 |
-
args.images_paths = None
|
| 25 |
-
args.images_folder = None
|
| 26 |
-
args.force_use_cpu = False
|
| 27 |
-
args.folder_name = 'test_measure_time'
|
| 28 |
-
args.config_from_file = 'run_configs/noise_shift_guidance_1_5.yaml'
|
| 29 |
-
args.save_intermediate_results = False
|
| 30 |
-
args.batch_size = None
|
| 31 |
-
args.skip_p_to_p = True
|
| 32 |
-
args.only_p_to_p = False
|
| 33 |
-
args.fp16 = False
|
| 34 |
-
args.prompts_file = 'dataset_measure_time/dataset.json'
|
| 35 |
-
args.images_in_prompts_file = None
|
| 36 |
-
args.seed = 986
|
| 37 |
-
args.time_measure_n = 1
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
assert (
|
| 41 |
-
args.batch_size is None or args.save_intermediate_results is False
|
| 42 |
-
), "save_intermediate_results is not implemented for batch_size > 1"
|
| 43 |
|
| 44 |
generator = None
|
| 45 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 46 |
|
| 47 |
-
BASE_MODEL = "stabilityai/sdxl-turbo"
|
| 48 |
-
|
| 49 |
lineart_detector = LineartDetector.from_pretrained("lllyasviel/Annotators")
|
| 50 |
lineart_detector = lineart_detector.to(device)
|
| 51 |
|
|
@@ -67,8 +45,8 @@ adapters = MultiAdapter(
|
|
| 67 |
)
|
| 68 |
adapters = adapters.to(torch.float16)
|
| 69 |
|
| 70 |
-
pipeline = DiffusionPipeline.
|
| 71 |
-
|
| 72 |
torch_dtype=torch.float16,
|
| 73 |
variant="fp16",
|
| 74 |
use_safetensors=True,
|
|
@@ -77,9 +55,8 @@ pipeline = DiffusionPipeline.from_pretrained(
|
|
| 77 |
)
|
| 78 |
pipeline = pipeline.to(device)
|
| 79 |
|
| 80 |
-
pipeline.scheduler = DDPMScheduler.
|
| 81 |
-
|
| 82 |
-
subfolder="scheduler",
|
| 83 |
)
|
| 84 |
|
| 85 |
config = get_config(args)
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import inversion_run_base
|
| 3 |
|
| 4 |
from diffusers import (
|
| 5 |
DDPMScheduler,
|
|
|
|
| 18 |
from functools import partial
|
| 19 |
from compel import Compel, ReturnedEmbeddingsType
|
| 20 |
|
| 21 |
+
|
| 22 |
+
args = inversion_run_base.args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
generator = None
|
| 25 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 26 |
|
|
|
|
|
|
|
| 27 |
lineart_detector = LineartDetector.from_pretrained("lllyasviel/Annotators")
|
| 28 |
lineart_detector = lineart_detector.to(device)
|
| 29 |
|
|
|
|
| 45 |
)
|
| 46 |
adapters = adapters.to(torch.float16)
|
| 47 |
|
| 48 |
+
pipeline = DiffusionPipeline.from_pipe(
|
| 49 |
+
inversion_run_base.pipeline,
|
| 50 |
torch_dtype=torch.float16,
|
| 51 |
variant="fp16",
|
| 52 |
use_safetensors=True,
|
|
|
|
| 55 |
)
|
| 56 |
pipeline = pipeline.to(device)
|
| 57 |
|
| 58 |
+
pipeline.scheduler = DDPMScheduler.from_config(
|
| 59 |
+
inversion_run_base.pipeline.scheduler.config,
|
|
|
|
| 60 |
)
|
| 61 |
|
| 62 |
config = get_config(args)
|