forked from sail-sg/EditAnything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (52 loc) · 3.22 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import os
from sam2edit import create_demo as create_demo_edit_anything
from sam2image import create_demo as create_demo_generate_anything
from sam2edit_beauty import create_demo as create_demo_beauty
from sam2edit_handsome import create_demo as create_demo_handsome
from sam2edit_lora import EditAnythingLoraModel, init_sam_model, init_blip_processor, init_blip_model
from huggingface_hub import hf_hub_download, snapshot_download
DESCRIPTION = f'''# [Edit Anything](https://github.com/sail-sg/EditAnything)
**Edit anything and keep the layout by segmenting anything in the image.**
'''
sam_generator, mask_predictor = init_sam_model()
blip_processor = init_blip_processor()
blip_model = init_blip_model()
sd_models_path = snapshot_download("shgao/sdmodels")
with gr.Blocks() as demo:
gr.Markdown(DESCRIPTION)
with gr.Tabs():
with gr.TabItem('🖌Edit Anything'):
model = EditAnythingLoraModel(base_model_path="stabilityai/stable-diffusion-2-inpainting",
controlmodel_name='LAION Pretrained(v0-4)-SD21',
lora_model_path=None, use_blip=True, extra_inpaint=False,
sam_generator=sam_generator,
mask_predictor=mask_predictor,
blip_processor=blip_processor,
blip_model=blip_model)
create_demo_edit_anything(model.process, model.process_image_click)
with gr.TabItem(' 👩🦰Beauty Edit/Generation'):
lora_model_path = hf_hub_download(
"mlida/Cute_girl_mix4", "cuteGirlMix4_v10.safetensors")
model = EditAnythingLoraModel(base_model_path=os.path.join(sd_models_path, "chilloutmix_NiPrunedFp32Fix"),
lora_model_path=lora_model_path, use_blip=True, extra_inpaint=True,
sam_generator=sam_generator,
mask_predictor=mask_predictor,
blip_processor=blip_processor,
blip_model=blip_model,
lora_weight=0.5,
)
create_demo_beauty(model.process, model.process_image_click)
with gr.TabItem(' 👨🌾Handsome Edit/Generation'):
model = EditAnythingLoraModel(base_model_path=os.path.join(sd_models_path, "Realistic_Vision_V2.0"),
lora_model_path=None, use_blip=True, extra_inpaint=True,
sam_generator=sam_generator,
mask_predictor=mask_predictor,
blip_processor=blip_processor,
blip_model=blip_model)
create_demo_handsome(model.process, model.process_image_click)
# with gr.TabItem('Generate Anything'):
# create_demo_generate_anything()
# with gr.Tabs():
# gr.Markdown(SHARED_UI_WARNING)
demo.queue(api_open=False).launch(server_name='0.0.0.0', share=False)