akhaliq HF Staff commited on
Commit
1cca0af
·
verified ·
1 Parent(s): a9ce589

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +378 -0
  2. requirements.txt +13 -0
app.py ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import spaces
4
+ from diffusers import OvisImagePipeline
5
+ from PIL import Image
6
+
7
+ # Initialize the pipeline globally
8
+ pipe = None
9
+
10
+ def load_model():
11
+ global pipe
12
+ if pipe is None:
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(
22
+ prompt: str,
23
+ negative_prompt: str,
24
+ num_inference_steps: int,
25
+ true_cfg_scale: float,
26
+ progress=gr.Progress(track_tqdm=True)
27
+ ):
28
+ if not prompt.strip():
29
+ raise gr.Error("Please enter a prompt to generate an image.")
30
+
31
+ progress(0, desc="Loading model...")
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
+ /* Global Apple-style design */
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, #f5f5f7 0%, #ffffff 100%) !important;
52
+ min-height: 100vh;
53
+ }
54
+
55
+ /* Header styling */
56
+ .header-container {
57
+ text-align: center;
58
+ padding: 40px 20px;
59
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
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: 3rem !important;
67
+ font-weight: 700 !important;
68
+ color: white !important;
69
+ margin: 0 !important;
70
+ letter-spacing: -0.02em;
71
+ }
72
+
73
+ .header-container p {
74
+ color: rgba(255, 255, 255, 0.9) !important;
75
+ font-size: 1.2rem !important;
76
+ margin-top: 12px !important;
77
+ font-weight: 400;
78
+ }
79
+
80
+ .header-container a {
81
+ color: rgba(255, 255, 255, 0.8) !important;
82
+ text-decoration: none;
83
+ transition: color 0.2s ease;
84
+ }
85
+
86
+ .header-container a:hover {
87
+ color: white !important;
88
+ }
89
+
90
+ /* Main container panels */
91
+ .main-panel {
92
+ background: white !important;
93
+ border-radius: 20px !important;
94
+ padding: 32px !important;
95
+ box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06) !important;
96
+ border: 1px solid rgba(0, 0, 0, 0.04) !important;
97
+ }
98
+
99
+ /* Input styling */
100
+ .input-container textarea, .input-container input {
101
+ border-radius: 12px !important;
102
+ border: 2px solid #e5e5ea !important;
103
+ padding: 16px !important;
104
+ font-size: 16px !important;
105
+ transition: all 0.3s ease !important;
106
+ background: #fafafa !important;
107
+ }
108
+
109
+ .input-container textarea:focus, .input-container input:focus {
110
+ border-color: #667eea !important;
111
+ box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15) !important;
112
+ background: white !important;
113
+ }
114
+
115
+ /* Labels */
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
+ /* Sliders */
124
+ input[type="range"] {
125
+ accent-color: #667eea !important;
126
+ }
127
+
128
+ /* Generate button */
129
+ .generate-btn {
130
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
131
+ border: none !important;
132
+ border-radius: 14px !important;
133
+ padding: 16px 32px !important;
134
+ font-size: 17px !important;
135
+ font-weight: 600 !important;
136
+ color: white !important;
137
+ cursor: pointer !important;
138
+ transition: all 0.3s ease !important;
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
+ .generate-btn:hover {
145
+ transform: translateY(-2px) !important;
146
+ box-shadow: 0 12px 32px rgba(102, 126, 234, 0.45) !important;
147
+ }
148
+
149
+ .generate-btn:active {
150
+ transform: translateY(0) !important;
151
+ }
152
+
153
+ /* Output image */
154
+ .output-image {
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
+ .output-image img {
161
+ border-radius: 16px !important;
162
+ }
163
+
164
+ /* Accordion */
165
+ .accordion {
166
+ border-radius: 16px !important;
167
+ border: 1px solid #e5e5ea !important;
168
+ overflow: hidden !important;
169
+ margin-top: 16px !important;
170
+ }
171
+
172
+ /* Examples section */
173
+ .examples-container {
174
+ background: #f5f5f7 !important;
175
+ border-radius: 16px !important;
176
+ padding: 24px !important;
177
+ margin-top: 24px !important;
178
+ }
179
+
180
+ /* Footer */
181
+ .footer-text {
182
+ text-align: center;
183
+ color: #86868b;
184
+ font-size: 13px;
185
+ margin-top: 32px;
186
+ padding: 16px;
187
+ }
188
+
189
+ .footer-text a {
190
+ color: #667eea;
191
+ text-decoration: none;
192
+ font-weight: 500;
193
+ }
194
+
195
+ /* Info text */
196
+ .info-text {
197
+ color: #86868b !important;
198
+ font-size: 13px !important;
199
+ }
200
+
201
+ /* Section titles */
202
+ .section-title {
203
+ font-size: 1.5rem !important;
204
+ font-weight: 600 !important;
205
+ color: #1d1d1f !important;
206
+ margin-bottom: 16px !important;
207
+ }
208
+
209
+ /* Zero GPU badge */
210
+ .zero-gpu-badge {
211
+ display: inline-block;
212
+ background: linear-gradient(135deg, #00c853 0%, #00e676 100%);
213
+ color: white;
214
+ padding: 4px 12px;
215
+ border-radius: 20px;
216
+ font-size: 12px;
217
+ font-weight: 600;
218
+ margin-left: 8px;
219
+ }
220
+ """
221
+
222
+ # Build the Gradio interface
223
+ with gr.Blocks(
224
+ title="OVIS Image Generator",
225
+ theme=gr.themes.Soft(
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>✨ OVIS Image <span class="zero-gpu-badge">⚡ ZeroGPU</span></h1>
241
+ <p>Transform your imagination into stunning visuals with AI</p>
242
+ <p style="font-size: 0.9rem; margin-top: 8px;">
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(equal_height=True):
249
+ # Left column - Inputs
250
+ with gr.Column(scale=1, elem_classes=["main-panel"]):
251
+ gr.Markdown("### 🎨 Create Your Image", elem_classes=["section-title"])
252
+
253
+ with gr.Group(elem_classes=["input-container"]):
254
+ prompt = gr.Textbox(
255
+ label="Prompt",
256
+ placeholder="Describe the image you want to create...",
257
+ lines=4,
258
+ max_lines=8,
259
+ info="Be descriptive! Include style, lighting, colors, and details."
260
+ )
261
+
262
+ with gr.Accordion("⚙️ Advanced Settings", open=False, elem_classes=["accordion"]):
263
+ negative_prompt = gr.Textbox(
264
+ label="Negative Prompt",
265
+ placeholder="What to avoid in the image...",
266
+ lines=2,
267
+ value="",
268
+ info="Describe elements you don't want in your image"
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=["main-panel"]):
298
+ gr.Markdown("### 🖼️ Generated Image", elem_classes=["section-title"])
299
+
300
+ output_image = gr.Image(
301
+ label="Result",
302
+ type="pil",
303
+ elem_classes=["output-image"],
304
+ height=512,
305
+ buttons=["download", "share", "fullscreen"]
306
+ )
307
+
308
+ # Examples section
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],
364
+ outputs=output_image,
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],
372
+ outputs=output_image,
373
+ api_visibility="public"
374
+ )
375
+
376
+ # Launch the app
377
+ if __name__ == "__main__":
378
+ demo.launch(css=apple_css)
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ spaces
2
+ git+https://github.com/huggingface/diffusers
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