-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_real_image_editing.py
88 lines (80 loc) · 1.94 KB
/
app_real_image_editing.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import numpy as np
import gradio as gr
from mdp import MDP
mdp_obj = MDP()
def real_image_editing(
image: np.ndarray,
sampler_type: str,
edit_prompt: str,
num_infer_steps: int,
tmax: int,
tm: int,
manip_schedule_type: str,
enable_classifier_free_guidance: bool,
guidance_scale: float
):
img, _ = mdp_obj.real_image_editing(
img_path=image,
sampler_type=sampler_type,
edit_prompt=edit_prompt,
num_infer_steps=num_infer_steps,
tmax=tmax,
tm=tm,
manip_schedule_type=manip_schedule_type,
enable_classifier_free_guidance=enable_classifier_free_guidance,
guidance_scale=guidance_scale
)
return np.asarray(img)
app_inputs = [
gr.Image(label="Input Image"),
gr.Dropdown(
label="Algorithm Type",
choices=['mdp_epsilon', 'mdp_condition', 'mdp_x', 'mdp_beta'],
value='mdp_epsilon'
),
gr.Textbox(
label="Text Prompt to Edit Image",
value="Photo of a zebra"
),
gr.Number(
label="Number of Inference Steps",
value=50,
precision=0
),
gr.Number(
label="T-max (end timestep)",
value=47,
precision=0
),
gr.Number(
label="T-m (total timesteps = end - start)",
value=26,
precision=0
),
gr.Dropdown(
label="Manipulation Schedule Type",
choices=['constant', 'linear', 'cosine', 'exp'],
value='constant'
),
gr.Checkbox(
label="Enable/Disable Classifier-free Guidance",
value=True,
),
gr.Number(
label="Guidance Scale (Valid only when guidance enabled)",
value=7.5,
precision=2
)
]
app_outputs = [
gr.Image(label="Edited Image")
]
demo = gr.Interface(
fn=real_image_editing,
inputs=app_inputs,
outputs=app_outputs,
title="Modifying Diffusion Path (MDP): Real Image Editing"
)
demo.queue()
demo.launch(share=True)