File size: 3,947 Bytes
8021e2e
6c0d858
 
61bbe53
6c0d858
f14200d
61bbe53
 
f14200d
 
 
 
 
61bbe53
babfe4f
 
 
 
 
 
 
2474e74
f14200d
 
 
 
 
61bbe53
 
 
f14200d
 
 
 
 
2474e74
f14200d
 
2474e74
f14200d
 
 
 
 
 
2474e74
f14200d
bc1676d
 
f14200d
2474e74
02dd2e1
 
 
 
 
 
 
 
11a775c
 
f14200d
 
61bbe53
2474e74
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
59
60
61
62
63
64
65
66
import subprocess
result = subprocess.run(
        ['pip', 'install', 'https://gradio-main-build.s3.amazonaws.com/bebfb72b353a4280155cf7070441fc476ac10172/gradio-3.28.3-py3-none-any.whl'], check=True)
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.**
'''
SHARED_UI_WARNING = f'''### [NOTE]  Inference may be slow in this shared UI.
You can duplicate and use it with a paid private GPU.
<a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/jyseo/3DFuse?duplicate=true"><img style="margin-top:0;margin-bottom:0" src="https://huggingface.co/datasets/huggingface/badges/raw/main/duplicate-this-space-xl-dark.svg" alt="Duplicate Space"></a>
'''
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)