Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files- app.py +279 -250
- requirements.txt +27 -5
app.py
CHANGED
|
@@ -2,20 +2,13 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
import spaces
|
| 4 |
from diffusers import OvisImagePipeline
|
| 5 |
-
from PIL import Image
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
pipe =
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
pipe = OvisImagePipeline.from_pretrained(
|
| 14 |
-
"AIDC-AI/Ovis-Image-7B",
|
| 15 |
-
torch_dtype=torch.bfloat16
|
| 16 |
-
)
|
| 17 |
-
pipe.to("cuda")
|
| 18 |
-
return pipe
|
| 19 |
|
| 20 |
@spaces.GPU(duration=120)
|
| 21 |
def generate_image(
|
|
@@ -28,336 +21,370 @@ def generate_image(
|
|
| 28 |
if not prompt.strip():
|
| 29 |
raise gr.Error("Please enter a prompt to generate an image.")
|
| 30 |
|
| 31 |
-
|
| 32 |
-
model = load_model()
|
| 33 |
-
|
| 34 |
-
progress(0.1, desc="Generating image...")
|
| 35 |
-
|
| 36 |
-
image = model(
|
| 37 |
prompt=prompt,
|
| 38 |
negative_prompt=negative_prompt if negative_prompt.strip() else "",
|
| 39 |
num_inference_steps=int(num_inference_steps),
|
| 40 |
true_cfg_scale=true_cfg_scale
|
| 41 |
).images[0]
|
| 42 |
|
| 43 |
-
progress(1, desc="Done!")
|
| 44 |
return image
|
| 45 |
|
| 46 |
# Apple-inspired CSS
|
| 47 |
apple_css = """
|
| 48 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
.gradio-container {
|
| 50 |
-
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif !important;
|
| 51 |
-
background: linear-gradient(180deg,
|
| 52 |
min-height: 100vh;
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
/* Header styling */
|
| 56 |
.header-container {
|
| 57 |
text-align: center;
|
| 58 |
-
padding:
|
| 59 |
-
|
| 60 |
-
border-radius: 24px;
|
| 61 |
-
margin-bottom: 32px;
|
| 62 |
-
box-shadow: 0 20px 60px rgba(102, 126, 234, 0.3);
|
| 63 |
}
|
| 64 |
|
| 65 |
.header-container h1 {
|
| 66 |
-
font-size:
|
| 67 |
-
font-weight:
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
.header-container p {
|
| 74 |
-
|
| 75 |
-
font-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
|
| 80 |
.header-container a {
|
| 81 |
-
color:
|
| 82 |
-
text-decoration: none;
|
| 83 |
-
transition:
|
| 84 |
}
|
| 85 |
|
| 86 |
.header-container a:hover {
|
| 87 |
-
|
| 88 |
}
|
| 89 |
|
| 90 |
-
/*
|
| 91 |
-
.
|
| 92 |
-
background: white !important;
|
| 93 |
-
border-radius:
|
| 94 |
padding: 32px !important;
|
| 95 |
-
box-shadow:
|
| 96 |
-
border: 1px solid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
-
/*
|
| 100 |
-
.
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
padding: 16px !important;
|
| 104 |
-
|
| 105 |
-
transition:
|
| 106 |
-
|
| 107 |
}
|
| 108 |
|
| 109 |
-
.
|
| 110 |
-
border-color:
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
}
|
| 114 |
|
| 115 |
-
|
| 116 |
-
.input-container label {
|
| 117 |
-
font-weight: 600 !important;
|
| 118 |
-
color: #1d1d1f !important;
|
| 119 |
font-size: 14px !important;
|
|
|
|
|
|
|
|
|
|
| 120 |
margin-bottom: 8px !important;
|
| 121 |
}
|
| 122 |
|
| 123 |
-
/*
|
| 124 |
-
input[type="range"] {
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
border
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
font-weight: 600 !important;
|
| 136 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
cursor: pointer !important;
|
| 138 |
-
|
| 139 |
-
box-shadow: 0 8px 24px rgba(102, 126, 234, 0.35) !important;
|
| 140 |
-
width: 100% !important;
|
| 141 |
-
margin-top: 16px !important;
|
| 142 |
}
|
| 143 |
|
| 144 |
-
.
|
| 145 |
-
|
| 146 |
-
|
| 147 |
}
|
| 148 |
|
| 149 |
-
.
|
| 150 |
-
|
|
|
|
| 151 |
}
|
| 152 |
|
| 153 |
-
|
| 154 |
-
.
|
| 155 |
-
border-radius: 16px !important;
|
| 156 |
-
overflow: hidden !important;
|
| 157 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
|
| 158 |
}
|
| 159 |
|
| 160 |
-
.
|
| 161 |
-
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
border-radius: 16px !important;
|
| 167 |
-
border: 1px solid #e5e5ea !important;
|
| 168 |
-
overflow: hidden !important;
|
| 169 |
-
margin-top: 16px !important;
|
| 170 |
}
|
| 171 |
|
| 172 |
-
/*
|
| 173 |
-
.
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
}
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
text-align: center;
|
| 183 |
-
color: #86868b;
|
| 184 |
-
font-size: 13px;
|
| 185 |
-
margin-top: 32px;
|
| 186 |
-
padding: 16px;
|
| 187 |
}
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
font-weight: 500;
|
| 193 |
}
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
color: #86868b !important;
|
| 198 |
-
font-size: 13px !important;
|
| 199 |
}
|
| 200 |
|
| 201 |
-
/* Section
|
| 202 |
-
.section-
|
| 203 |
-
font-size:
|
| 204 |
font-weight: 600 !important;
|
| 205 |
-
color:
|
|
|
|
|
|
|
| 206 |
margin-bottom: 16px !important;
|
| 207 |
}
|
| 208 |
|
| 209 |
-
/*
|
| 210 |
-
.
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
}
|
| 220 |
"""
|
| 221 |
|
| 222 |
-
# Build the Gradio interface
|
| 223 |
with gr.Blocks(
|
| 224 |
title="OVIS Image Generator",
|
| 225 |
-
|
| 226 |
-
primary_hue="violet",
|
| 227 |
-
secondary_hue="purple",
|
| 228 |
-
neutral_hue="slate",
|
| 229 |
-
font=gr.themes.GoogleFont("Inter")
|
| 230 |
-
),
|
| 231 |
-
fill_width=True,
|
| 232 |
-
footer_links=[
|
| 233 |
-
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
|
| 234 |
-
]
|
| 235 |
) as demo:
|
| 236 |
-
|
| 237 |
# Header
|
| 238 |
gr.HTML("""
|
| 239 |
<div class="header-container">
|
| 240 |
-
<h1
|
| 241 |
-
<p>
|
| 242 |
-
<p style="
|
| 243 |
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
|
| 244 |
</p>
|
| 245 |
</div>
|
| 246 |
""")
|
| 247 |
|
| 248 |
-
with gr.Row(
|
| 249 |
-
# Left column -
|
| 250 |
-
with gr.Column(scale=1, elem_classes=
|
| 251 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
)
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
)
|
| 270 |
-
|
| 271 |
-
with gr.Row():
|
| 272 |
-
num_steps = gr.Slider(
|
| 273 |
-
label="Inference Steps",
|
| 274 |
-
minimum=10,
|
| 275 |
-
maximum=100,
|
| 276 |
-
value=50,
|
| 277 |
-
step=5,
|
| 278 |
-
info="More steps = higher quality but slower"
|
| 279 |
-
)
|
| 280 |
-
|
| 281 |
-
cfg_scale = gr.Slider(
|
| 282 |
-
label="CFG Scale",
|
| 283 |
-
minimum=1.0,
|
| 284 |
-
maximum=15.0,
|
| 285 |
-
value=5.0,
|
| 286 |
-
step=0.5,
|
| 287 |
-
info="How closely to follow the prompt"
|
| 288 |
-
)
|
| 289 |
-
|
| 290 |
-
generate_btn = gr.Button(
|
| 291 |
-
"✨ Generate Image",
|
| 292 |
-
variant="primary",
|
| 293 |
-
elem_classes=["generate-btn"]
|
| 294 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
# Right column - Output
|
| 297 |
-
with gr.Column(scale=1, elem_classes=
|
| 298 |
-
gr.
|
| 299 |
|
| 300 |
output_image = gr.Image(
|
| 301 |
-
label="
|
| 302 |
type="pil",
|
| 303 |
-
|
| 304 |
-
height=512
|
| 305 |
-
buttons=["download", "share", "fullscreen"]
|
| 306 |
)
|
| 307 |
|
| 308 |
-
#
|
| 309 |
-
with gr.Row():
|
| 310 |
-
with gr.Column(elem_classes=["examples-container"]):
|
| 311 |
-
gr.Markdown("### 💡 Example Prompts")
|
| 312 |
-
gr.Examples(
|
| 313 |
-
examples=[
|
| 314 |
-
[
|
| 315 |
-
'A creative 3D artistic render where the text "OVIS-IMAGE" is written in a bold, expressive handwritten brush style using thick, wet oil paint. The paint is a mix of vibrant rainbow colors (red, blue, yellow) swirling together like toothpaste or impasto art. You can see the ridges of the brush bristles and the glossy, wet texture of the paint. The background is a clean artist\'s canvas. Dynamic lighting creates soft shadows behind the floating paint strokes. Colorful, expressive, tactile texture, 4k detail.',
|
| 316 |
-
"",
|
| 317 |
-
50,
|
| 318 |
-
5.0
|
| 319 |
-
],
|
| 320 |
-
[
|
| 321 |
-
"A serene Japanese zen garden at sunrise, with carefully raked sand patterns, moss-covered stones, and a small wooden bridge over a koi pond. Cherry blossom petals gently falling. Soft morning light, photorealistic, 8k quality.",
|
| 322 |
-
"cartoon, anime, illustration",
|
| 323 |
-
50,
|
| 324 |
-
5.0
|
| 325 |
-
],
|
| 326 |
-
[
|
| 327 |
-
"A majestic snow leopard resting on a rocky mountain peak, overlooking a vast valley below. Golden hour lighting, cinematic composition, National Geographic style photography, ultra detailed fur texture.",
|
| 328 |
-
"blurry, low quality",
|
| 329 |
-
50,
|
| 330 |
-
5.0
|
| 331 |
-
],
|
| 332 |
-
[
|
| 333 |
-
"An enchanted library with floating books, magical glowing orbs, ancient wooden shelves reaching to the ceiling, dust particles in beams of light, fantasy art style, highly detailed, mystical atmosphere.",
|
| 334 |
-
"",
|
| 335 |
-
50,
|
| 336 |
-
5.0
|
| 337 |
-
],
|
| 338 |
-
[
|
| 339 |
-
"A futuristic cyberpunk cityscape at night, neon signs in Japanese and English, flying cars, holographic advertisements, rain-slicked streets reflecting colorful lights, blade runner aesthetic, 4k cinematic.",
|
| 340 |
-
"daytime, bright, sunny",
|
| 341 |
-
50,
|
| 342 |
-
5.0
|
| 343 |
-
],
|
| 344 |
-
],
|
| 345 |
-
inputs=[prompt, negative_prompt, num_steps, cfg_scale],
|
| 346 |
-
label="Click an example to try it"
|
| 347 |
-
)
|
| 348 |
-
|
| 349 |
-
# Footer
|
| 350 |
-
gr.HTML("""
|
| 351 |
-
<div class="footer-text">
|
| 352 |
-
<p>Powered by <strong>OVIS-Image-7B</strong> from AIDC-AI · Running on <strong>ZeroGPU</strong></p>
|
| 353 |
-
<p>
|
| 354 |
-
<a href="https://huggingface.co/AIDC-AI/Ovis-Image-7B" target="_blank">Model Card</a> ·
|
| 355 |
-
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
|
| 356 |
-
</p>
|
| 357 |
-
</div>
|
| 358 |
-
""")
|
| 359 |
-
|
| 360 |
-
# Event handler
|
| 361 |
generate_btn.click(
|
| 362 |
fn=generate_image,
|
| 363 |
inputs=[prompt, negative_prompt, num_steps, cfg_scale],
|
|
@@ -365,7 +392,6 @@ with gr.Blocks(
|
|
| 365 |
api_visibility="public"
|
| 366 |
)
|
| 367 |
|
| 368 |
-
# Also trigger on Enter key in prompt
|
| 369 |
prompt.submit(
|
| 370 |
fn=generate_image,
|
| 371 |
inputs=[prompt, negative_prompt, num_steps, cfg_scale],
|
|
@@ -373,6 +399,9 @@ with gr.Blocks(
|
|
| 373 |
api_visibility="public"
|
| 374 |
)
|
| 375 |
|
| 376 |
-
# Launch the app
|
| 377 |
if __name__ == "__main__":
|
| 378 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
import spaces
|
| 4 |
from diffusers import OvisImagePipeline
|
|
|
|
| 5 |
|
| 6 |
+
# Load the model at startup
|
| 7 |
+
pipe = OvisImagePipeline.from_pretrained(
|
| 8 |
+
"AIDC-AI/Ovis-Image-7B",
|
| 9 |
+
torch_dtype=torch.bfloat16
|
| 10 |
+
)
|
| 11 |
+
pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
@spaces.GPU(duration=120)
|
| 14 |
def generate_image(
|
|
|
|
| 21 |
if not prompt.strip():
|
| 22 |
raise gr.Error("Please enter a prompt to generate an image.")
|
| 23 |
|
| 24 |
+
image = pipe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
prompt=prompt,
|
| 26 |
negative_prompt=negative_prompt if negative_prompt.strip() else "",
|
| 27 |
num_inference_steps=int(num_inference_steps),
|
| 28 |
true_cfg_scale=true_cfg_scale
|
| 29 |
).images[0]
|
| 30 |
|
|
|
|
| 31 |
return image
|
| 32 |
|
| 33 |
# Apple-inspired CSS
|
| 34 |
apple_css = """
|
| 35 |
+
/* Apple-style design system */
|
| 36 |
+
@import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&family=SF+Pro+Text:wght@400;500;600&display=swap');
|
| 37 |
+
|
| 38 |
+
:root {
|
| 39 |
+
--apple-blue: #0071e3;
|
| 40 |
+
--apple-blue-hover: #0077ED;
|
| 41 |
+
--apple-gray-1: #f5f5f7;
|
| 42 |
+
--apple-gray-2: #e8e8ed;
|
| 43 |
+
--apple-gray-3: #d2d2d7;
|
| 44 |
+
--apple-gray-4: #86868b;
|
| 45 |
+
--apple-gray-5: #1d1d1f;
|
| 46 |
+
--apple-white: #ffffff;
|
| 47 |
+
--apple-black: #000000;
|
| 48 |
+
--apple-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
|
| 49 |
+
--apple-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.12);
|
| 50 |
+
--apple-radius: 12px;
|
| 51 |
+
--apple-radius-lg: 18px;
|
| 52 |
+
--apple-transition: all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* Base styles */
|
| 56 |
.gradio-container {
|
| 57 |
+
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
|
| 58 |
+
background: linear-gradient(180deg, var(--apple-gray-1) 0%, var(--apple-white) 100%) !important;
|
| 59 |
min-height: 100vh;
|
| 60 |
+
max-width: 1200px !important;
|
| 61 |
+
margin: 0 auto !important;
|
| 62 |
+
padding: 40px 20px !important;
|
| 63 |
}
|
| 64 |
|
| 65 |
/* Header styling */
|
| 66 |
.header-container {
|
| 67 |
text-align: center;
|
| 68 |
+
padding: 60px 20px 40px;
|
| 69 |
+
margin-bottom: 40px;
|
|
|
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
.header-container h1 {
|
| 73 |
+
font-size: 56px !important;
|
| 74 |
+
font-weight: 600 !important;
|
| 75 |
+
letter-spacing: -0.02em !important;
|
| 76 |
+
color: var(--apple-gray-5) !important;
|
| 77 |
+
margin-bottom: 16px !important;
|
| 78 |
+
line-height: 1.1 !important;
|
| 79 |
}
|
| 80 |
|
| 81 |
.header-container p {
|
| 82 |
+
font-size: 21px !important;
|
| 83 |
+
font-weight: 400 !important;
|
| 84 |
+
color: var(--apple-gray-4) !important;
|
| 85 |
+
max-width: 600px;
|
| 86 |
+
margin: 0 auto !important;
|
| 87 |
+
line-height: 1.5 !important;
|
| 88 |
}
|
| 89 |
|
| 90 |
.header-container a {
|
| 91 |
+
color: var(--apple-blue) !important;
|
| 92 |
+
text-decoration: none !important;
|
| 93 |
+
transition: var(--apple-transition);
|
| 94 |
}
|
| 95 |
|
| 96 |
.header-container a:hover {
|
| 97 |
+
text-decoration: underline !important;
|
| 98 |
}
|
| 99 |
|
| 100 |
+
/* Card-like containers */
|
| 101 |
+
.input-section, .output-section {
|
| 102 |
+
background: var(--apple-white) !important;
|
| 103 |
+
border-radius: var(--apple-radius-lg) !important;
|
| 104 |
padding: 32px !important;
|
| 105 |
+
box-shadow: var(--apple-shadow) !important;
|
| 106 |
+
border: 1px solid var(--apple-gray-2) !important;
|
| 107 |
+
transition: var(--apple-transition);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.input-section:hover, .output-section:hover {
|
| 111 |
+
box-shadow: var(--apple-shadow-hover) !important;
|
| 112 |
}
|
| 113 |
|
| 114 |
+
/* Textbox styling */
|
| 115 |
+
.gradio-textbox textarea, .gradio-textbox input {
|
| 116 |
+
font-family: inherit !important;
|
| 117 |
+
font-size: 17px !important;
|
| 118 |
+
border: 2px solid var(--apple-gray-2) !important;
|
| 119 |
+
border-radius: var(--apple-radius) !important;
|
| 120 |
padding: 16px !important;
|
| 121 |
+
background: var(--apple-gray-1) !important;
|
| 122 |
+
transition: var(--apple-transition);
|
| 123 |
+
color: var(--apple-gray-5) !important;
|
| 124 |
}
|
| 125 |
|
| 126 |
+
.gradio-textbox textarea:focus, .gradio-textbox input:focus {
|
| 127 |
+
border-color: var(--apple-blue) !important;
|
| 128 |
+
background: var(--apple-white) !important;
|
| 129 |
+
outline: none !important;
|
| 130 |
+
box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15) !important;
|
| 131 |
}
|
| 132 |
|
| 133 |
+
.gradio-textbox label {
|
|
|
|
|
|
|
|
|
|
| 134 |
font-size: 14px !important;
|
| 135 |
+
font-weight: 600 !important;
|
| 136 |
+
color: var(--apple-gray-5) !important;
|
| 137 |
+
letter-spacing: -0.01em !important;
|
| 138 |
margin-bottom: 8px !important;
|
| 139 |
}
|
| 140 |
|
| 141 |
+
/* Slider styling */
|
| 142 |
+
.gradio-slider input[type="range"] {
|
| 143 |
+
height: 6px !important;
|
| 144 |
+
background: var(--apple-gray-2) !important;
|
| 145 |
+
border-radius: 3px !important;
|
| 146 |
}
|
| 147 |
|
| 148 |
+
.gradio-slider input[type="range"]::-webkit-slider-thumb {
|
| 149 |
+
width: 22px !important;
|
| 150 |
+
height: 22px !important;
|
| 151 |
+
background: var(--apple-white) !important;
|
| 152 |
+
border: 2px solid var(--apple-gray-3) !important;
|
| 153 |
+
border-radius: 50% !important;
|
| 154 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
|
| 155 |
+
cursor: pointer !important;
|
| 156 |
+
transition: var(--apple-transition);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.gradio-slider input[type="range"]::-webkit-slider-thumb:hover {
|
| 160 |
+
transform: scale(1.1);
|
| 161 |
+
border-color: var(--apple-blue) !important;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
.gradio-slider label {
|
| 165 |
+
font-size: 14px !important;
|
| 166 |
font-weight: 600 !important;
|
| 167 |
+
color: var(--apple-gray-5) !important;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.gradio-slider .wrap {
|
| 171 |
+
background: transparent !important;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* Button styling */
|
| 175 |
+
.gradio-button {
|
| 176 |
+
font-family: inherit !important;
|
| 177 |
+
font-size: 17px !important;
|
| 178 |
+
font-weight: 500 !important;
|
| 179 |
+
border-radius: 980px !important;
|
| 180 |
+
padding: 16px 32px !important;
|
| 181 |
+
transition: var(--apple-transition);
|
| 182 |
+
border: none !important;
|
| 183 |
cursor: pointer !important;
|
| 184 |
+
letter-spacing: -0.01em !important;
|
|
|
|
|
|
|
|
|
|
| 185 |
}
|
| 186 |
|
| 187 |
+
.gradio-button.primary {
|
| 188 |
+
background: var(--apple-blue) !important;
|
| 189 |
+
color: var(--apple-white) !important;
|
| 190 |
}
|
| 191 |
|
| 192 |
+
.gradio-button.primary:hover {
|
| 193 |
+
background: var(--apple-blue-hover) !important;
|
| 194 |
+
transform: scale(1.02);
|
| 195 |
}
|
| 196 |
|
| 197 |
+
.gradio-button.primary:active {
|
| 198 |
+
transform: scale(0.98);
|
|
|
|
|
|
|
|
|
|
| 199 |
}
|
| 200 |
|
| 201 |
+
.gradio-button.secondary {
|
| 202 |
+
background: var(--apple-gray-1) !important;
|
| 203 |
+
color: var(--apple-blue) !important;
|
| 204 |
}
|
| 205 |
|
| 206 |
+
.gradio-button.secondary:hover {
|
| 207 |
+
background: var(--apple-gray-2) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
}
|
| 209 |
|
| 210 |
+
/* Image output styling */
|
| 211 |
+
.gradio-image {
|
| 212 |
+
border-radius: var(--apple-radius-lg) !important;
|
| 213 |
+
overflow: hidden !important;
|
| 214 |
+
background: var(--apple-gray-1) !important;
|
| 215 |
+
border: 1px solid var(--apple-gray-2) !important;
|
| 216 |
}
|
| 217 |
|
| 218 |
+
.gradio-image img {
|
| 219 |
+
border-radius: var(--apple-radius) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
}
|
| 221 |
|
| 222 |
+
/* Row and column spacing */
|
| 223 |
+
.gradio-row {
|
| 224 |
+
gap: 16px !important;
|
|
|
|
| 225 |
}
|
| 226 |
|
| 227 |
+
.gradio-column {
|
| 228 |
+
gap: 16px !important;
|
|
|
|
|
|
|
| 229 |
}
|
| 230 |
|
| 231 |
+
/* Section labels */
|
| 232 |
+
.section-label {
|
| 233 |
+
font-size: 13px !important;
|
| 234 |
font-weight: 600 !important;
|
| 235 |
+
color: var(--apple-gray-4) !important;
|
| 236 |
+
text-transform: uppercase !important;
|
| 237 |
+
letter-spacing: 0.02em !important;
|
| 238 |
margin-bottom: 16px !important;
|
| 239 |
}
|
| 240 |
|
| 241 |
+
/* Slider container */
|
| 242 |
+
.slider-row {
|
| 243 |
+
background: var(--apple-gray-1) !important;
|
| 244 |
+
border-radius: var(--apple-radius) !important;
|
| 245 |
+
padding: 20px !important;
|
| 246 |
+
margin-top: 8px !important;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
/* Footer link styling */
|
| 250 |
+
.built-with {
|
| 251 |
+
text-align: center;
|
| 252 |
+
padding: 40px 20px;
|
| 253 |
+
color: var(--apple-gray-4);
|
| 254 |
+
font-size: 14px;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
.built-with a {
|
| 258 |
+
color: var(--apple-blue) !important;
|
| 259 |
+
text-decoration: none !important;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
.built-with a:hover {
|
| 263 |
+
text-decoration: underline !important;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/* Progress bar */
|
| 267 |
+
.progress-bar {
|
| 268 |
+
background: var(--apple-gray-2) !important;
|
| 269 |
+
border-radius: 4px !important;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
.progress-bar > div {
|
| 273 |
+
background: linear-gradient(90deg, var(--apple-blue), #34C759) !important;
|
| 274 |
+
border-radius: 4px !important;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
/* Placeholder text */
|
| 278 |
+
::placeholder {
|
| 279 |
+
color: var(--apple-gray-4) !important;
|
| 280 |
+
opacity: 1 !important;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/* Remove default borders and shadows */
|
| 284 |
+
.block {
|
| 285 |
+
border: none !important;
|
| 286 |
+
box-shadow: none !important;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
/* Group styling */
|
| 290 |
+
.group {
|
| 291 |
+
background: var(--apple-white) !important;
|
| 292 |
+
border-radius: var(--apple-radius-lg) !important;
|
| 293 |
+
padding: 24px !important;
|
| 294 |
+
box-shadow: var(--apple-shadow) !important;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
/* Accordion styling */
|
| 298 |
+
.gradio-accordion {
|
| 299 |
+
border: 1px solid var(--apple-gray-2) !important;
|
| 300 |
+
border-radius: var(--apple-radius) !important;
|
| 301 |
+
overflow: hidden !important;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
.gradio-accordion > button {
|
| 305 |
+
background: var(--apple-gray-1) !important;
|
| 306 |
+
font-weight: 500 !important;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
/* Hide default footer items we don't want */
|
| 310 |
+
footer {
|
| 311 |
+
opacity: 0.7;
|
| 312 |
}
|
| 313 |
"""
|
| 314 |
|
|
|
|
| 315 |
with gr.Blocks(
|
| 316 |
title="OVIS Image Generator",
|
| 317 |
+
css=apple_css
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
) as demo:
|
|
|
|
| 319 |
# Header
|
| 320 |
gr.HTML("""
|
| 321 |
<div class="header-container">
|
| 322 |
+
<h1>OVIS Image</h1>
|
| 323 |
+
<p>Create stunning images with OVIS-Image-7B. Simply describe what you imagine.</p>
|
| 324 |
+
<p style="margin-top: 12px; font-size: 14px;">
|
| 325 |
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
|
| 326 |
</p>
|
| 327 |
</div>
|
| 328 |
""")
|
| 329 |
|
| 330 |
+
with gr.Row():
|
| 331 |
+
# Left column - Input
|
| 332 |
+
with gr.Column(scale=1, elem_classes="input-section"):
|
| 333 |
+
gr.HTML('<div class="section-label">Create</div>')
|
| 334 |
+
|
| 335 |
+
prompt = gr.Textbox(
|
| 336 |
+
label="Prompt",
|
| 337 |
+
placeholder="Describe the image you want to create...",
|
| 338 |
+
lines=4,
|
| 339 |
+
elem_id="prompt-input"
|
| 340 |
+
)
|
| 341 |
|
| 342 |
+
negative_prompt = gr.Textbox(
|
| 343 |
+
label="Negative Prompt",
|
| 344 |
+
placeholder="What to avoid (optional)...",
|
| 345 |
+
lines=2
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
gr.HTML('<div class="section-label" style="margin-top: 24px;">Settings</div>')
|
| 349 |
+
|
| 350 |
+
with gr.Group(elem_classes="slider-row"):
|
| 351 |
+
num_steps = gr.Slider(
|
| 352 |
+
label="Inference Steps",
|
| 353 |
+
minimum=10,
|
| 354 |
+
maximum=100,
|
| 355 |
+
value=50,
|
| 356 |
+
step=5,
|
| 357 |
+
info="More steps = higher quality, slower generation"
|
| 358 |
)
|
| 359 |
|
| 360 |
+
cfg_scale = gr.Slider(
|
| 361 |
+
label="CFG Scale",
|
| 362 |
+
minimum=1.0,
|
| 363 |
+
maximum=15.0,
|
| 364 |
+
value=5.0,
|
| 365 |
+
step=0.5,
|
| 366 |
+
info="How closely to follow your prompt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
)
|
| 368 |
+
|
| 369 |
+
generate_btn = gr.Button(
|
| 370 |
+
"Generate Image",
|
| 371 |
+
variant="primary",
|
| 372 |
+
size="lg",
|
| 373 |
+
elem_id="generate-btn"
|
| 374 |
+
)
|
| 375 |
|
| 376 |
# Right column - Output
|
| 377 |
+
with gr.Column(scale=1, elem_classes="output-section"):
|
| 378 |
+
gr.HTML('<div class="section-label">Result</div>')
|
| 379 |
|
| 380 |
output_image = gr.Image(
|
| 381 |
+
label="Generated Image",
|
| 382 |
type="pil",
|
| 383 |
+
elem_id="output-image",
|
| 384 |
+
height=512
|
|
|
|
| 385 |
)
|
| 386 |
|
| 387 |
+
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
generate_btn.click(
|
| 389 |
fn=generate_image,
|
| 390 |
inputs=[prompt, negative_prompt, num_steps, cfg_scale],
|
|
|
|
| 392 |
api_visibility="public"
|
| 393 |
)
|
| 394 |
|
|
|
|
| 395 |
prompt.submit(
|
| 396 |
fn=generate_image,
|
| 397 |
inputs=[prompt, negative_prompt, num_steps, cfg_scale],
|
|
|
|
| 399 |
api_visibility="public"
|
| 400 |
)
|
| 401 |
|
|
|
|
| 402 |
if __name__ == "__main__":
|
| 403 |
+
demo.launch(
|
| 404 |
+
footer_links=[
|
| 405 |
+
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
|
| 406 |
+
]
|
| 407 |
+
)
|
requirements.txt
CHANGED
|
@@ -1,13 +1,35 @@
|
|
| 1 |
spaces
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
git+https://github.com/huggingface/transformers
|
| 4 |
sentencepiece
|
| 5 |
accelerate
|
| 6 |
-
torch
|
| 7 |
-
torchvision
|
| 8 |
-
torchaudio
|
| 9 |
tokenizers
|
| 10 |
datasets
|
| 11 |
-
gradio
|
| 12 |
requests
|
| 13 |
Pillow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
spaces
|
| 2 |
+
gradio
|
| 3 |
+
git+https://github.com/huggingface/diffusers
|
| 4 |
+
torch
|
| 5 |
git+https://github.com/huggingface/transformers
|
| 6 |
sentencepiece
|
| 7 |
accelerate
|
|
|
|
|
|
|
|
|
|
| 8 |
tokenizers
|
| 9 |
datasets
|
|
|
|
| 10 |
requests
|
| 11 |
Pillow
|
| 12 |
+
torchvision
|
| 13 |
+
torchaudio
|
| 14 |
+
numpy
|
| 15 |
+
scipy
|
| 16 |
+
opencv-python
|
| 17 |
+
matplotlib
|
| 18 |
+
tqdm
|
| 19 |
+
safetensors
|
| 20 |
+
pillow-heif
|
| 21 |
+
xformers
|
| 22 |
+
omegaconf
|
| 23 |
+
ftfy
|
| 24 |
+
regex
|
| 25 |
+
einops
|
| 26 |
+
timm
|
| 27 |
+
webdataset
|
| 28 |
+
wandb
|
| 29 |
+
tensorboard
|
| 30 |
+
huggingface-hub
|
| 31 |
+
safetensors
|
| 32 |
+
bitsandbytes
|
| 33 |
+
peft
|
| 34 |
+
diffusers
|
| 35 |
+
transformers
|