Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,30 +3,47 @@ from PIL import Image, ImageDraw, ImageFont
|
|
| 3 |
import random
|
| 4 |
|
| 5 |
def generate_image(prompt):
|
| 6 |
-
# Create blank
|
| 7 |
-
img = Image.new("RGB", (512, 512),
|
| 8 |
draw = ImageDraw.Draw(img)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
for
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
x2 = random.randint(0, 512)
|
| 15 |
-
y2 = random.randint(0, 512)
|
| 16 |
-
draw.line((x1, y1, x2, y2), fill=(0, 0, 0), width=1)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
return img
|
| 23 |
|
| 24 |
-
|
| 25 |
fn=generate_image,
|
| 26 |
inputs=gr.Textbox(label="Describe the image"),
|
| 27 |
outputs=gr.Image(label="Generated Image"),
|
| 28 |
title="⚡ Dave AI — Instant Image Generator",
|
| 29 |
-
description="
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
|
|
|
| 3 |
import random
|
| 4 |
|
| 5 |
def generate_image(prompt):
|
| 6 |
+
# Create blank canvas
|
| 7 |
+
img = Image.new("RGB", (512, 512), (20, 20, 30))
|
| 8 |
draw = ImageDraw.Draw(img)
|
| 9 |
|
| 10 |
+
# Add background gradient
|
| 11 |
+
for i in range(512):
|
| 12 |
+
color = (20 + i // 20, 20 + i // 25, 30 + i // 15)
|
| 13 |
+
draw.line([(0, i), (512, i)], fill=color)
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Simple “cartoon” shapes based on prompt
|
| 16 |
+
shapes = ["circle", "square", "triangle", "star"]
|
| 17 |
+
shape = random.choice(shapes)
|
| 18 |
+
|
| 19 |
+
# Draw shape
|
| 20 |
+
if shape == "circle":
|
| 21 |
+
draw.ellipse([100, 120, 412, 420], outline="white", width=6)
|
| 22 |
+
elif shape == "square":
|
| 23 |
+
draw.rectangle([120, 120, 392, 392], outline="white", width=6)
|
| 24 |
+
elif shape == "triangle":
|
| 25 |
+
draw.polygon([(256, 120), (120, 420), (392, 420)], outline="white", width=6)
|
| 26 |
+
else:
|
| 27 |
+
# star
|
| 28 |
+
draw.polygon(
|
| 29 |
+
[(256, 120), (290, 250), (420, 260), (310, 330),
|
| 30 |
+
(340, 460), (256, 370), (172, 460), (202, 330),
|
| 31 |
+
(92, 260), (222, 250)],
|
| 32 |
+
outline="white", width=6
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Add prompt text at bottom
|
| 36 |
+
draw.rectangle([0, 470, 512, 512], fill=(0, 0, 0))
|
| 37 |
+
draw.text((10, 472), f"Prompt: {prompt[:30]}", fill="white")
|
| 38 |
|
| 39 |
return img
|
| 40 |
|
| 41 |
+
demo = gr.Interface(
|
| 42 |
fn=generate_image,
|
| 43 |
inputs=gr.Textbox(label="Describe the image"),
|
| 44 |
outputs=gr.Image(label="Generated Image"),
|
| 45 |
title="⚡ Dave AI — Instant Image Generator",
|
| 46 |
+
description="Fast CPU-only generator. No tokens. No GPU.",
|
| 47 |
)
|
| 48 |
|
| 49 |
+
demo.launch()
|