File size: 11,065 Bytes
1cca0af
 
 
 
 
63b9ac2
 
 
 
 
 
1cca0af
 
 
 
 
 
 
 
 
 
 
 
63b9ac2
1cca0af
 
 
 
 
 
 
 
 
 
63b9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cca0af
63b9ac2
 
1cca0af
63b9ac2
 
 
1cca0af
 
 
 
 
63b9ac2
 
1cca0af
 
 
63b9ac2
 
 
 
 
 
1cca0af
 
 
63b9ac2
 
 
 
 
 
1cca0af
 
 
63b9ac2
 
 
1cca0af
 
 
63b9ac2
1cca0af
 
63b9ac2
 
 
 
1cca0af
63b9ac2
 
 
 
 
 
 
1cca0af
 
63b9ac2
 
 
 
 
 
1cca0af
63b9ac2
 
 
1cca0af
 
63b9ac2
 
 
 
 
1cca0af
 
63b9ac2
1cca0af
63b9ac2
 
 
1cca0af
 
 
63b9ac2
 
 
 
 
1cca0af
 
63b9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cca0af
63b9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cca0af
63b9ac2
1cca0af
 
63b9ac2
 
 
1cca0af
 
63b9ac2
 
 
1cca0af
 
63b9ac2
 
1cca0af
 
63b9ac2
 
 
1cca0af
 
63b9ac2
 
1cca0af
 
63b9ac2
 
 
 
 
 
1cca0af
 
63b9ac2
 
1cca0af
 
63b9ac2
 
 
1cca0af
 
63b9ac2
 
1cca0af
 
63b9ac2
 
 
1cca0af
63b9ac2
 
 
1cca0af
 
 
63b9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cca0af
 
 
 
 
63b9ac2
1cca0af
 
 
 
63b9ac2
 
 
1cca0af
 
 
 
 
63b9ac2
 
 
 
 
 
 
 
 
 
 
1cca0af
63b9ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cca0af
 
63b9ac2
 
 
 
 
 
 
1cca0af
63b9ac2
 
 
 
 
 
 
1cca0af
 
63b9ac2
 
1cca0af
 
63b9ac2
1cca0af
63b9ac2
 
1cca0af
 
63b9ac2
1cca0af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63b9ac2
 
 
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import gradio as gr
import torch
import spaces
from diffusers import OvisImagePipeline

# Load the model at startup
pipe = OvisImagePipeline.from_pretrained(
    "AIDC-AI/Ovis-Image-7B", 
    torch_dtype=torch.bfloat16
)
pipe.to("cuda")

@spaces.GPU(duration=120)
def generate_image(
    prompt: str,
    negative_prompt: str,
    num_inference_steps: int,
    true_cfg_scale: float,
    progress=gr.Progress(track_tqdm=True)
):
    if not prompt.strip():
        raise gr.Error("Please enter a prompt to generate an image.")
    
    image = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt if negative_prompt.strip() else "",
        num_inference_steps=int(num_inference_steps),
        true_cfg_scale=true_cfg_scale
    ).images[0]
    
    return image

# Apple-inspired CSS
apple_css = """
/* Apple-style design system */
@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');

:root {
    --apple-blue: #0071e3;
    --apple-blue-hover: #0077ED;
    --apple-gray-1: #f5f5f7;
    --apple-gray-2: #e8e8ed;
    --apple-gray-3: #d2d2d7;
    --apple-gray-4: #86868b;
    --apple-gray-5: #1d1d1f;
    --apple-white: #ffffff;
    --apple-black: #000000;
    --apple-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --apple-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.12);
    --apple-radius: 12px;
    --apple-radius-lg: 18px;
    --apple-transition: all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Base styles */
.gradio-container {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
    background: linear-gradient(180deg, var(--apple-gray-1) 0%, var(--apple-white) 100%) !important;
    min-height: 100vh;
    max-width: 1200px !important;
    margin: 0 auto !important;
    padding: 40px 20px !important;
}

/* Header styling */
.header-container {
    text-align: center;
    padding: 60px 20px 40px;
    margin-bottom: 40px;
}

.header-container h1 {
    font-size: 56px !important;
    font-weight: 600 !important;
    letter-spacing: -0.02em !important;
    color: var(--apple-gray-5) !important;
    margin-bottom: 16px !important;
    line-height: 1.1 !important;
}

.header-container p {
    font-size: 21px !important;
    font-weight: 400 !important;
    color: var(--apple-gray-4) !important;
    max-width: 600px;
    margin: 0 auto !important;
    line-height: 1.5 !important;
}

.header-container a {
    color: var(--apple-blue) !important;
    text-decoration: none !important;
    transition: var(--apple-transition);
}

.header-container a:hover {
    text-decoration: underline !important;
}

/* Card-like containers */
.input-section, .output-section {
    background: var(--apple-white) !important;
    border-radius: var(--apple-radius-lg) !important;
    padding: 32px !important;
    box-shadow: var(--apple-shadow) !important;
    border: 1px solid var(--apple-gray-2) !important;
    transition: var(--apple-transition);
}

.input-section:hover, .output-section:hover {
    box-shadow: var(--apple-shadow-hover) !important;
}

/* Textbox styling */
.gradio-textbox textarea, .gradio-textbox input {
    font-family: inherit !important;
    font-size: 17px !important;
    border: 2px solid var(--apple-gray-2) !important;
    border-radius: var(--apple-radius) !important;
    padding: 16px !important;
    background: var(--apple-gray-1) !important;
    transition: var(--apple-transition);
    color: var(--apple-gray-5) !important;
}

.gradio-textbox textarea:focus, .gradio-textbox input:focus {
    border-color: var(--apple-blue) !important;
    background: var(--apple-white) !important;
    outline: none !important;
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15) !important;
}

.gradio-textbox label {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: var(--apple-gray-5) !important;
    letter-spacing: -0.01em !important;
    margin-bottom: 8px !important;
}

/* Slider styling */
.gradio-slider input[type="range"] {
    height: 6px !important;
    background: var(--apple-gray-2) !important;
    border-radius: 3px !important;
}

.gradio-slider input[type="range"]::-webkit-slider-thumb {
    width: 22px !important;
    height: 22px !important;
    background: var(--apple-white) !important;
    border: 2px solid var(--apple-gray-3) !important;
    border-radius: 50% !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    cursor: pointer !important;
    transition: var(--apple-transition);
}

.gradio-slider input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    border-color: var(--apple-blue) !important;
}

.gradio-slider label {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: var(--apple-gray-5) !important;
}

.gradio-slider .wrap {
    background: transparent !important;
}

/* Button styling */
.gradio-button {
    font-family: inherit !important;
    font-size: 17px !important;
    font-weight: 500 !important;
    border-radius: 980px !important;
    padding: 16px 32px !important;
    transition: var(--apple-transition);
    border: none !important;
    cursor: pointer !important;
    letter-spacing: -0.01em !important;
}

.gradio-button.primary {
    background: var(--apple-blue) !important;
    color: var(--apple-white) !important;
}

.gradio-button.primary:hover {
    background: var(--apple-blue-hover) !important;
    transform: scale(1.02);
}

.gradio-button.primary:active {
    transform: scale(0.98);
}

.gradio-button.secondary {
    background: var(--apple-gray-1) !important;
    color: var(--apple-blue) !important;
}

.gradio-button.secondary:hover {
    background: var(--apple-gray-2) !important;
}

/* Image output styling */
.gradio-image {
    border-radius: var(--apple-radius-lg) !important;
    overflow: hidden !important;
    background: var(--apple-gray-1) !important;
    border: 1px solid var(--apple-gray-2) !important;
}

.gradio-image img {
    border-radius: var(--apple-radius) !important;
}

/* Row and column spacing */
.gradio-row {
    gap: 16px !important;
}

.gradio-column {
    gap: 16px !important;
}

/* Section labels */
.section-label {
    font-size: 13px !important;
    font-weight: 600 !important;
    color: var(--apple-gray-4) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.02em !important;
    margin-bottom: 16px !important;
}

/* Slider container */
.slider-row {
    background: var(--apple-gray-1) !important;
    border-radius: var(--apple-radius) !important;
    padding: 20px !important;
    margin-top: 8px !important;
}

/* Footer link styling */
.built-with {
    text-align: center;
    padding: 40px 20px;
    color: var(--apple-gray-4);
    font-size: 14px;
}

.built-with a {
    color: var(--apple-blue) !important;
    text-decoration: none !important;
}

.built-with a:hover {
    text-decoration: underline !important;
}

/* Progress bar */
.progress-bar {
    background: var(--apple-gray-2) !important;
    border-radius: 4px !important;
}

.progress-bar > div {
    background: linear-gradient(90deg, var(--apple-blue), #34C759) !important;
    border-radius: 4px !important;
}

/* Placeholder text */
::placeholder {
    color: var(--apple-gray-4) !important;
    opacity: 1 !important;
}

/* Remove default borders and shadows */
.block {
    border: none !important;
    box-shadow: none !important;
}

/* Group styling */
.group {
    background: var(--apple-white) !important;
    border-radius: var(--apple-radius-lg) !important;
    padding: 24px !important;
    box-shadow: var(--apple-shadow) !important;
}

/* Accordion styling */
.gradio-accordion {
    border: 1px solid var(--apple-gray-2) !important;
    border-radius: var(--apple-radius) !important;
    overflow: hidden !important;
}

.gradio-accordion > button {
    background: var(--apple-gray-1) !important;
    font-weight: 500 !important;
}

/* Hide default footer items we don't want */
footer {
    opacity: 0.7;
}
"""

with gr.Blocks(
    title="OVIS Image Generator",
    css=apple_css
) as demo:
    # Header
    gr.HTML("""
        <div class="header-container">
            <h1>OVIS Image</h1>
            <p>Create stunning images with OVIS-Image-7B. Simply describe what you imagine.</p>
            <p style="margin-top: 12px; font-size: 14px;">
                <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
            </p>
        </div>
    """)
    
    with gr.Row():
        # Left column - Input
        with gr.Column(scale=1, elem_classes="input-section"):
            gr.HTML('<div class="section-label">Create</div>')
            
            prompt = gr.Textbox(
                label="Prompt",
                placeholder="Describe the image you want to create...",
                lines=4,
                elem_id="prompt-input"
            )
            
            negative_prompt = gr.Textbox(
                label="Negative Prompt",
                placeholder="What to avoid (optional)...",
                lines=2
            )
            
            gr.HTML('<div class="section-label" style="margin-top: 24px;">Settings</div>')
            
            with gr.Group(elem_classes="slider-row"):
                num_steps = gr.Slider(
                    label="Inference Steps",
                    minimum=10,
                    maximum=100,
                    value=50,
                    step=5,
                    info="More steps = higher quality, slower generation"
                )
                
                cfg_scale = gr.Slider(
                    label="CFG Scale",
                    minimum=1.0,
                    maximum=15.0,
                    value=5.0,
                    step=0.5,
                    info="How closely to follow your prompt"
                )
            
            generate_btn = gr.Button(
                "Generate Image",
                variant="primary",
                size="lg",
                elem_id="generate-btn"
            )
        
        # Right column - Output
        with gr.Column(scale=1, elem_classes="output-section"):
            gr.HTML('<div class="section-label">Result</div>')
            
            output_image = gr.Image(
                label="Generated Image",
                type="pil",
                elem_id="output-image",
                height=512
            )
    
    # Event handlers
    generate_btn.click(
        fn=generate_image,
        inputs=[prompt, negative_prompt, num_steps, cfg_scale],
        outputs=output_image,
        api_visibility="public"
    )
    
    prompt.submit(
        fn=generate_image,
        inputs=[prompt, negative_prompt, num_steps, cfg_scale],
        outputs=output_image,
        api_visibility="public"
    )

if __name__ == "__main__":
    demo.launch(
        footer_links=[
            {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
        ]
    )