Spaces:
Running
on
Zero
Running
on
Zero
generation
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ from transformers import AutoTokenizer, AutoModel
|
|
| 11 |
from models.gen_pipeline import NextStepPipeline
|
| 12 |
from utils.aspect_ratio import center_crop_arr_with_buckets
|
| 13 |
|
| 14 |
-
HF_HUB = "stepfun-ai/NextStep-1-Large
|
| 15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained(HF_HUB, local_files_only=False, trust_remote_code=True)
|
|
@@ -30,15 +30,15 @@ def infer(
|
|
| 30 |
ref=None,
|
| 31 |
seed=0,
|
| 32 |
text_cfg=7.5,
|
| 33 |
-
img_cfg=
|
| 34 |
num_inference_steps=30,
|
| 35 |
positive_prompt=DEFAULT_POSITIVE_PROMPT,
|
| 36 |
negative_prompt=DEFAULT_NEGATIVE_PROMPT,
|
| 37 |
progress=gr.Progress(track_tqdm=True),
|
| 38 |
):
|
| 39 |
-
if ref is None:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
if prompt in [None, ""]:
|
| 44 |
gr.Warning("⚠️ Please enter a prompt!")
|
|
@@ -55,8 +55,7 @@ def infer(
|
|
| 55 |
|
| 56 |
image = pipeline.generate_image(
|
| 57 |
captions=editing_caption,
|
| 58 |
-
|
| 59 |
-
num_images_per_caption=2,
|
| 60 |
positive_prompt=positive_prompt,
|
| 61 |
negative_prompt=negative_prompt,
|
| 62 |
hw=(input_image.size[1], input_image.size[0]),
|
|
@@ -69,15 +68,7 @@ def infer(
|
|
| 69 |
progress=True,
|
| 70 |
)
|
| 71 |
|
| 72 |
-
return image[0]
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
examples = [
|
| 76 |
-
["Modify the image to make the white horse run towards the camera.", "assets/1.jpg"],
|
| 77 |
-
["Change the background to the sea view.", "assets/2.jpg"],
|
| 78 |
-
["Add a pirate hat to the dog's head. Change the background to a stormy sea with dark clouds. Include the text 'NextStep-Edit' in bold white letters at the top portion of the image.", "assets/3.jpg"],
|
| 79 |
-
["Change to Ghibli style.", "assets/4.jpg"],
|
| 80 |
-
]
|
| 81 |
|
| 82 |
css = """
|
| 83 |
#col-container {
|
|
@@ -102,13 +93,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 102 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 103 |
|
| 104 |
with gr.Row():
|
| 105 |
-
ref = gr.Image(label="Reference Image", show_label=True, type="pil", height=400)
|
| 106 |
|
| 107 |
with gr.Accordion("Advanced Settings", open=True):
|
| 108 |
positive_prompt = gr.Text(
|
| 109 |
label="Positive Prompt",
|
| 110 |
show_label=False,
|
| 111 |
-
max_lines=
|
| 112 |
placeholder="Enter your positive prompt",
|
| 113 |
container=False,
|
| 114 |
)
|
|
@@ -153,9 +144,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 153 |
|
| 154 |
with gr.Row():
|
| 155 |
result_1 = gr.Image(label="Result 1", show_label=False, container=True, height=400, visible=False)
|
| 156 |
-
result_2 = gr.Image(label="Result 2", show_label=False, container=True, height=400, visible=False)
|
| 157 |
|
| 158 |
-
gr.Examples(examples=examples, inputs=[prompt, ref])
|
| 159 |
|
| 160 |
def show_result():
|
| 161 |
return gr.update(visible=True), gr.update(visible=True)
|
|
@@ -165,7 +156,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 165 |
fn=infer,
|
| 166 |
inputs=[
|
| 167 |
prompt,
|
| 168 |
-
ref,
|
| 169 |
seed,
|
| 170 |
text_cfg,
|
| 171 |
img_cfg,
|
|
@@ -173,13 +164,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 173 |
positive_prompt,
|
| 174 |
negative_prompt,
|
| 175 |
],
|
| 176 |
-
outputs=[result_1
|
| 177 |
)
|
| 178 |
|
| 179 |
gr.on(
|
| 180 |
triggers=[run_button.click, prompt.submit],
|
| 181 |
fn=show_result,
|
| 182 |
-
outputs=[result_1
|
| 183 |
)
|
| 184 |
|
| 185 |
|
|
|
|
| 11 |
from models.gen_pipeline import NextStepPipeline
|
| 12 |
from utils.aspect_ratio import center_crop_arr_with_buckets
|
| 13 |
|
| 14 |
+
HF_HUB = "stepfun-ai/NextStep-1-Large"
|
| 15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained(HF_HUB, local_files_only=False, trust_remote_code=True)
|
|
|
|
| 30 |
ref=None,
|
| 31 |
seed=0,
|
| 32 |
text_cfg=7.5,
|
| 33 |
+
img_cfg=1.0,
|
| 34 |
num_inference_steps=30,
|
| 35 |
positive_prompt=DEFAULT_POSITIVE_PROMPT,
|
| 36 |
negative_prompt=DEFAULT_NEGATIVE_PROMPT,
|
| 37 |
progress=gr.Progress(track_tqdm=True),
|
| 38 |
):
|
| 39 |
+
#if ref is None:
|
| 40 |
+
# gr.Warning("⚠️ Please upload an image!")
|
| 41 |
+
# return None
|
| 42 |
|
| 43 |
if prompt in [None, ""]:
|
| 44 |
gr.Warning("⚠️ Please enter a prompt!")
|
|
|
|
| 55 |
|
| 56 |
image = pipeline.generate_image(
|
| 57 |
captions=editing_caption,
|
| 58 |
+
num_images_per_caption=1,
|
|
|
|
| 59 |
positive_prompt=positive_prompt,
|
| 60 |
negative_prompt=negative_prompt,
|
| 61 |
hw=(input_image.size[1], input_image.size[0]),
|
|
|
|
| 68 |
progress=True,
|
| 69 |
)
|
| 70 |
|
| 71 |
+
return image[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
css = """
|
| 74 |
#col-container {
|
|
|
|
| 93 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
+
#ref = gr.Image(label="Reference Image", show_label=True, type="pil", height=400)
|
| 97 |
|
| 98 |
with gr.Accordion("Advanced Settings", open=True):
|
| 99 |
positive_prompt = gr.Text(
|
| 100 |
label="Positive Prompt",
|
| 101 |
show_label=False,
|
| 102 |
+
max_lines=1,
|
| 103 |
placeholder="Enter your positive prompt",
|
| 104 |
container=False,
|
| 105 |
)
|
|
|
|
| 144 |
|
| 145 |
with gr.Row():
|
| 146 |
result_1 = gr.Image(label="Result 1", show_label=False, container=True, height=400, visible=False)
|
| 147 |
+
#result_2 = gr.Image(label="Result 2", show_label=False, container=True, height=400, visible=False)
|
| 148 |
|
| 149 |
+
#gr.Examples(examples=examples, inputs=[prompt, ref])
|
| 150 |
|
| 151 |
def show_result():
|
| 152 |
return gr.update(visible=True), gr.update(visible=True)
|
|
|
|
| 156 |
fn=infer,
|
| 157 |
inputs=[
|
| 158 |
prompt,
|
| 159 |
+
#ref,
|
| 160 |
seed,
|
| 161 |
text_cfg,
|
| 162 |
img_cfg,
|
|
|
|
| 164 |
positive_prompt,
|
| 165 |
negative_prompt,
|
| 166 |
],
|
| 167 |
+
outputs=[result_1],
|
| 168 |
)
|
| 169 |
|
| 170 |
gr.on(
|
| 171 |
triggers=[run_button.click, prompt.submit],
|
| 172 |
fn=show_result,
|
| 173 |
+
outputs=[result_1],
|
| 174 |
)
|
| 175 |
|
| 176 |
|