Spaces:
Paused
Paused
Add RL model and curated examples
Browse files- .gitattributes +6 -0
- README.md +7 -1
- app.py +161 -22
- assets/examples/blue_mug_1024.png +3 -0
- assets/examples/blue_mug_1536.png +3 -0
- assets/examples/desk_lamp_1024.png +3 -0
- assets/examples/desk_lamp_1536.png +3 -0
- assets/examples/red_apple_1024.png +3 -0
- assets/examples/red_apple_1536.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/examples/blue_mug_1024.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/examples/blue_mug_1536.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
assets/examples/desk_lamp_1024.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/examples/desk_lamp_1536.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
assets/examples/red_apple_1024.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
assets/examples/red_apple_1536.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -9,6 +9,7 @@ models:
|
|
| 9 |
- SeFi-Image/SeFi-Image-1B-Base
|
| 10 |
- SeFi-Image/SeFi-Image-2B-Base
|
| 11 |
- SeFi-Image/SeFi-Image-5B-Base
|
|
|
|
| 12 |
- SeFi-Image/SeFi-Image-1B-turbo
|
| 13 |
- SeFi-Image/SeFi-Image-2B-turbo
|
| 14 |
- SeFi-Image/SeFi-Image-5B-turbo
|
|
@@ -16,19 +17,24 @@ models:
|
|
| 16 |
|
| 17 |
# SeFi Image ZeroGPU
|
| 18 |
|
| 19 |
-
Public Gradio ZeroGPU Space for SeFi-Image 1B, 2B, and 5B Base/Turbo checkpoints.
|
| 20 |
|
| 21 |
The model defaults match the SeFi model cards:
|
| 22 |
|
| 23 |
| Family | Models | Steps | Guidance |
|
| 24 |
| --- | --- | ---: | ---: |
|
| 25 |
| Base | 1B, 2B, 5B | 50 | 4.0 |
|
|
|
|
| 26 |
| Turbo | 1B, 2B, 5B | 4 | 1.0 |
|
| 27 |
|
| 28 |
The SeFi checkpoints are gated under CC BY-NC 4.0. The Space uses an `HF_TOKEN`
|
| 29 |
secret to download model files, so the Space owner account must first be approved
|
| 30 |
for each selected SeFi model repository.
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
The vendored `sefi/` inference package comes from
|
| 33 |
`jmliu206/SeFi-Image` at commit `2f02744a187639ee41a296f8177cbbe7e5f333f5`
|
| 34 |
and is covered by `LICENSE-SEFI-INFERENCE`.
|
|
|
|
| 9 |
- SeFi-Image/SeFi-Image-1B-Base
|
| 10 |
- SeFi-Image/SeFi-Image-2B-Base
|
| 11 |
- SeFi-Image/SeFi-Image-5B-Base
|
| 12 |
+
- SeFi-Image/SeFi-Image-5B-RL
|
| 13 |
- SeFi-Image/SeFi-Image-1B-turbo
|
| 14 |
- SeFi-Image/SeFi-Image-2B-turbo
|
| 15 |
- SeFi-Image/SeFi-Image-5B-turbo
|
|
|
|
| 17 |
|
| 18 |
# SeFi Image ZeroGPU
|
| 19 |
|
| 20 |
+
Public Gradio ZeroGPU Space for SeFi-Image 1B, 2B, and 5B Base/RL/Turbo checkpoints.
|
| 21 |
|
| 22 |
The model defaults match the SeFi model cards:
|
| 23 |
|
| 24 |
| Family | Models | Steps | Guidance |
|
| 25 |
| --- | --- | ---: | ---: |
|
| 26 |
| Base | 1B, 2B, 5B | 50 | 4.0 |
|
| 27 |
+
| RL | 5B | 50 | 4.0 |
|
| 28 |
| Turbo | 1B, 2B, 5B | 4 | 1.0 |
|
| 29 |
|
| 30 |
The SeFi checkpoints are gated under CC BY-NC 4.0. The Space uses an `HF_TOKEN`
|
| 31 |
secret to download model files, so the Space owner account must first be approved
|
| 32 |
for each selected SeFi model repository.
|
| 33 |
|
| 34 |
+
The included examples were generated from this Space with `SeFi-Image-1B-turbo`
|
| 35 |
+
at 1024x1024 and 1536x1536. Selecting an example fills the prompt, parameters,
|
| 36 |
+
seed, and output image.
|
| 37 |
+
|
| 38 |
The vendored `sefi/` inference package comes from
|
| 39 |
`jmliu206/SeFi-Image` at commit `2f02744a187639ee41a296f8177cbbe7e5f333f5`
|
| 40 |
and is covered by `LICENSE-SEFI-INFERENCE`.
|
app.py
CHANGED
|
@@ -10,7 +10,6 @@ from dataclasses import dataclass
|
|
| 10 |
import gradio as gr
|
| 11 |
import spaces
|
| 12 |
import torch
|
| 13 |
-
from huggingface_hub import hf_hub_download
|
| 14 |
|
| 15 |
from sefi import SEFIInferencePipeline
|
| 16 |
|
|
@@ -55,6 +54,13 @@ MODEL_PRESETS: dict[str, ModelPreset] = {
|
|
| 55 |
steps=50,
|
| 56 |
guidance=4.0,
|
| 57 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
"1b-turbo": ModelPreset(
|
| 59 |
label="SeFi-Image 1B Turbo",
|
| 60 |
repo_id="SeFi-Image/SeFi-Image-1B-turbo",
|
|
@@ -80,21 +86,120 @@ MODEL_PRESETS: dict[str, ModelPreset] = {
|
|
| 80 |
|
| 81 |
DEFAULT_MODEL = "1b-turbo"
|
| 82 |
TURBO_STEPS = {4, 8, 10}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
_MODEL_LOCK = threading.Lock()
|
| 85 |
_LOADED_MODEL_KEY: str | None = None
|
| 86 |
_LOADED_PIPE: SEFIInferencePipeline | None = None
|
| 87 |
|
| 88 |
|
| 89 |
-
def _hf_token() -> str | None:
|
| 90 |
-
token = os.getenv("HF_TOKEN")
|
| 91 |
-
return token.strip() if token and token.strip() else None
|
| 92 |
-
|
| 93 |
-
|
| 94 |
def _model_choices() -> list[tuple[str, str]]:
|
| 95 |
return [(preset.label, key) for key, preset in MODEL_PRESETS.items()]
|
| 96 |
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
def _torch_cleanup() -> None:
|
| 99 |
gc.collect()
|
| 100 |
if torch.cuda.is_available():
|
|
@@ -161,19 +266,27 @@ def model_defaults(model_key: str):
|
|
| 161 |
)
|
| 162 |
|
| 163 |
|
| 164 |
-
def
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
|
| 179 |
def estimate_duration(
|
|
@@ -313,10 +426,9 @@ with gr.Blocks(title="SeFi Image ZeroGPU") as demo:
|
|
| 313 |
minimum=0,
|
| 314 |
maximum=2**31 - 1,
|
| 315 |
)
|
| 316 |
-
randomize_seed = gr.Checkbox(label="Randomize", value=
|
| 317 |
with gr.Row():
|
| 318 |
run = gr.Button("Generate", variant="primary")
|
| 319 |
-
access = gr.Button("Check Access")
|
| 320 |
|
| 321 |
with gr.Column(scale=1, min_width=360):
|
| 322 |
image = gr.Image(label="Image", type="pil", format="png")
|
|
@@ -328,8 +440,35 @@ with gr.Blocks(title="SeFi Image ZeroGPU") as demo:
|
|
| 328 |
)
|
| 329 |
)
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
model.change(model_defaults, inputs=model, outputs=[steps, guidance, status])
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
run.click(
|
| 334 |
generate,
|
| 335 |
inputs=[
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
import spaces
|
| 12 |
import torch
|
|
|
|
| 13 |
|
| 14 |
from sefi import SEFIInferencePipeline
|
| 15 |
|
|
|
|
| 54 |
steps=50,
|
| 55 |
guidance=4.0,
|
| 56 |
),
|
| 57 |
+
"5b-rl": ModelPreset(
|
| 58 |
+
label="SeFi-Image 5B RL",
|
| 59 |
+
repo_id="SeFi-Image/SeFi-Image-5B-RL",
|
| 60 |
+
family="rl",
|
| 61 |
+
steps=50,
|
| 62 |
+
guidance=4.0,
|
| 63 |
+
),
|
| 64 |
"1b-turbo": ModelPreset(
|
| 65 |
label="SeFi-Image 1B Turbo",
|
| 66 |
repo_id="SeFi-Image/SeFi-Image-1B-turbo",
|
|
|
|
| 86 |
|
| 87 |
DEFAULT_MODEL = "1b-turbo"
|
| 88 |
TURBO_STEPS = {4, 8, 10}
|
| 89 |
+
EXAMPLES = [
|
| 90 |
+
{
|
| 91 |
+
"label": "Blue mug 1024",
|
| 92 |
+
"model_key": "1b-turbo",
|
| 93 |
+
"prompt": (
|
| 94 |
+
"A blue ceramic mug on a white desk, morning light, minimal clean "
|
| 95 |
+
"background, high detail product photo."
|
| 96 |
+
),
|
| 97 |
+
"steps": 4,
|
| 98 |
+
"guidance": 1.0,
|
| 99 |
+
"width": 1024,
|
| 100 |
+
"height": 1024,
|
| 101 |
+
"seed": 6201,
|
| 102 |
+
"image": "assets/examples/blue_mug_1024.png",
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"label": "Blue mug 1536",
|
| 106 |
+
"model_key": "1b-turbo",
|
| 107 |
+
"prompt": (
|
| 108 |
+
"A blue ceramic mug on a white desk, morning light, minimal clean "
|
| 109 |
+
"background, high detail product photo."
|
| 110 |
+
),
|
| 111 |
+
"steps": 4,
|
| 112 |
+
"guidance": 1.0,
|
| 113 |
+
"width": 1536,
|
| 114 |
+
"height": 1536,
|
| 115 |
+
"seed": 6201,
|
| 116 |
+
"image": "assets/examples/blue_mug_1536.png",
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"label": "Red apple 1024",
|
| 120 |
+
"model_key": "1b-turbo",
|
| 121 |
+
"prompt": (
|
| 122 |
+
"A red apple on a wooden table, soft natural window light, simple "
|
| 123 |
+
"product photograph, sharp focus."
|
| 124 |
+
),
|
| 125 |
+
"steps": 4,
|
| 126 |
+
"guidance": 1.0,
|
| 127 |
+
"width": 1024,
|
| 128 |
+
"height": 1024,
|
| 129 |
+
"seed": 6202,
|
| 130 |
+
"image": "assets/examples/red_apple_1024.png",
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"label": "Red apple 1536",
|
| 134 |
+
"model_key": "1b-turbo",
|
| 135 |
+
"prompt": (
|
| 136 |
+
"A red apple on a wooden table, soft natural window light, simple "
|
| 137 |
+
"product photograph, sharp focus."
|
| 138 |
+
),
|
| 139 |
+
"steps": 4,
|
| 140 |
+
"guidance": 1.0,
|
| 141 |
+
"width": 1536,
|
| 142 |
+
"height": 1536,
|
| 143 |
+
"seed": 6202,
|
| 144 |
+
"image": "assets/examples/red_apple_1536.png",
|
| 145 |
+
},
|
| 146 |
+
{
|
| 147 |
+
"label": "Desk lamp 1024",
|
| 148 |
+
"model_key": "1b-turbo",
|
| 149 |
+
"prompt": (
|
| 150 |
+
"A modern brass desk lamp on a walnut writing table, warm evening "
|
| 151 |
+
"light, realistic product photography, uncluttered background."
|
| 152 |
+
),
|
| 153 |
+
"steps": 4,
|
| 154 |
+
"guidance": 1.0,
|
| 155 |
+
"width": 1024,
|
| 156 |
+
"height": 1024,
|
| 157 |
+
"seed": 6203,
|
| 158 |
+
"image": "assets/examples/desk_lamp_1024.png",
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"label": "Desk lamp 1536",
|
| 162 |
+
"model_key": "1b-turbo",
|
| 163 |
+
"prompt": (
|
| 164 |
+
"A modern brass desk lamp on a walnut writing table, warm evening "
|
| 165 |
+
"light, realistic product photography, uncluttered background."
|
| 166 |
+
),
|
| 167 |
+
"steps": 4,
|
| 168 |
+
"guidance": 1.0,
|
| 169 |
+
"width": 1536,
|
| 170 |
+
"height": 1536,
|
| 171 |
+
"seed": 6203,
|
| 172 |
+
"image": "assets/examples/desk_lamp_1536.png",
|
| 173 |
+
},
|
| 174 |
+
]
|
| 175 |
|
| 176 |
_MODEL_LOCK = threading.Lock()
|
| 177 |
_LOADED_MODEL_KEY: str | None = None
|
| 178 |
_LOADED_PIPE: SEFIInferencePipeline | None = None
|
| 179 |
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
def _model_choices() -> list[tuple[str, str]]:
|
| 182 |
return [(preset.label, key) for key, preset in MODEL_PRESETS.items()]
|
| 183 |
|
| 184 |
|
| 185 |
+
def _example_rows() -> list[list[str | int | float]]:
|
| 186 |
+
rows = []
|
| 187 |
+
for example in EXAMPLES:
|
| 188 |
+
preset = MODEL_PRESETS[str(example["model_key"])]
|
| 189 |
+
rows.append(
|
| 190 |
+
[
|
| 191 |
+
str(example["label"]),
|
| 192 |
+
preset.label,
|
| 193 |
+
str(example["prompt"]),
|
| 194 |
+
f'{example["width"]}x{example["height"]}',
|
| 195 |
+
int(example["steps"]),
|
| 196 |
+
float(example["guidance"]),
|
| 197 |
+
int(example["seed"]),
|
| 198 |
+
]
|
| 199 |
+
)
|
| 200 |
+
return rows
|
| 201 |
+
|
| 202 |
+
|
| 203 |
def _torch_cleanup() -> None:
|
| 204 |
gc.collect()
|
| 205 |
if torch.cuda.is_available():
|
|
|
|
| 266 |
)
|
| 267 |
|
| 268 |
|
| 269 |
+
def load_example(evt: gr.SelectData):
|
| 270 |
+
index = evt.index[0] if isinstance(evt.index, (list, tuple)) else evt.index
|
| 271 |
+
example = EXAMPLES[int(index)]
|
| 272 |
+
preset = MODEL_PRESETS[str(example["model_key"])]
|
| 273 |
+
status = (
|
| 274 |
+
f'Loaded example "{example["label"]}" generated with `{preset.repo_id}` '
|
| 275 |
+
f'at {example["width"]}x{example["height"]}, {example["steps"]} steps, '
|
| 276 |
+
f'guidance {example["guidance"]}, seed {example["seed"]}.'
|
| 277 |
+
)
|
| 278 |
+
return (
|
| 279 |
+
example["model_key"],
|
| 280 |
+
example["prompt"],
|
| 281 |
+
example["steps"],
|
| 282 |
+
example["guidance"],
|
| 283 |
+
example["width"],
|
| 284 |
+
example["height"],
|
| 285 |
+
example["seed"],
|
| 286 |
+
False,
|
| 287 |
+
example["image"],
|
| 288 |
+
status,
|
| 289 |
+
)
|
| 290 |
|
| 291 |
|
| 292 |
def estimate_duration(
|
|
|
|
| 426 |
minimum=0,
|
| 427 |
maximum=2**31 - 1,
|
| 428 |
)
|
| 429 |
+
randomize_seed = gr.Checkbox(label="Randomize", value=True)
|
| 430 |
with gr.Row():
|
| 431 |
run = gr.Button("Generate", variant="primary")
|
|
|
|
| 432 |
|
| 433 |
with gr.Column(scale=1, min_width=360):
|
| 434 |
image = gr.Image(label="Image", type="pil", format="png")
|
|
|
|
| 440 |
)
|
| 441 |
)
|
| 442 |
|
| 443 |
+
examples = gr.Dataframe(
|
| 444 |
+
value=_example_rows(),
|
| 445 |
+
headers=["Example", "Model", "Prompt", "Size", "Steps", "Guidance", "Seed"],
|
| 446 |
+
datatype=["str", "str", "str", "str", "number", "number", "number"],
|
| 447 |
+
type="array",
|
| 448 |
+
label="Examples",
|
| 449 |
+
interactive=False,
|
| 450 |
+
wrap=True,
|
| 451 |
+
max_height=260,
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
model.change(model_defaults, inputs=model, outputs=[steps, guidance, status])
|
| 455 |
+
examples.select(
|
| 456 |
+
load_example,
|
| 457 |
+
outputs=[
|
| 458 |
+
model,
|
| 459 |
+
prompt,
|
| 460 |
+
steps,
|
| 461 |
+
guidance,
|
| 462 |
+
width,
|
| 463 |
+
height,
|
| 464 |
+
seed,
|
| 465 |
+
randomize_seed,
|
| 466 |
+
image,
|
| 467 |
+
status,
|
| 468 |
+
],
|
| 469 |
+
api_name="load_example",
|
| 470 |
+
api_visibility="undocumented",
|
| 471 |
+
)
|
| 472 |
run.click(
|
| 473 |
generate,
|
| 474 |
inputs=[
|
assets/examples/blue_mug_1024.png
ADDED
|
Git LFS Details
|
assets/examples/blue_mug_1536.png
ADDED
|
Git LFS Details
|
assets/examples/desk_lamp_1024.png
ADDED
|
Git LFS Details
|
assets/examples/desk_lamp_1536.png
ADDED
|
Git LFS Details
|
assets/examples/red_apple_1024.png
ADDED
|
Git LFS Details
|
assets/examples/red_apple_1536.png
ADDED
|
Git LFS Details
|