Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,37 +2,44 @@ import gradio as gr
|
|
| 2 |
from PIL import Image, ImageDraw, ImageFont
|
| 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 |
-
#
|
| 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 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
draw.ellipse(
|
| 22 |
-
|
| 23 |
-
draw.
|
| 24 |
-
|
| 25 |
-
draw.
|
|
|
|
| 26 |
else:
|
| 27 |
-
|
| 28 |
-
|
| 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 |
|
|
|
|
| 2 |
from PIL import Image, ImageDraw, ImageFont
|
| 3 |
import random
|
| 4 |
|
| 5 |
+
def draw_rat(draw):
|
| 6 |
+
# Body
|
| 7 |
+
draw.ellipse((170, 240, 340, 380), outline="white", width=6)
|
| 8 |
+
# Head
|
| 9 |
+
draw.ellipse((120, 260, 210, 330), outline="white", width=6)
|
| 10 |
+
# Ears
|
| 11 |
+
draw.ellipse((130, 240, 160, 270), outline="white", width=6)
|
| 12 |
+
draw.ellipse((180, 240, 210, 270), outline="white", width=6)
|
| 13 |
+
# Tail
|
| 14 |
+
draw.line((340, 320, 450, 260), fill="white", width=6)
|
| 15 |
+
# Eyes
|
| 16 |
+
draw.ellipse((155, 285, 165, 295), fill="white")
|
| 17 |
+
draw.ellipse((185, 285, 195, 295), fill="white")
|
| 18 |
+
|
| 19 |
def generate_image(prompt):
|
|
|
|
| 20 |
img = Image.new("RGB", (512, 512), (20, 20, 30))
|
| 21 |
draw = ImageDraw.Draw(img)
|
| 22 |
|
| 23 |
+
# Background
|
| 24 |
for i in range(512):
|
| 25 |
color = (20 + i // 20, 20 + i // 25, 30 + i // 15)
|
| 26 |
draw.line([(0, i), (512, i)], fill=color)
|
| 27 |
|
| 28 |
+
# Basic prompt detection
|
| 29 |
+
prompt_lower = prompt.lower()
|
| 30 |
+
if "rat" in prompt_lower:
|
| 31 |
+
draw_rat(draw)
|
| 32 |
+
elif "cat" in prompt_lower:
|
| 33 |
+
draw.ellipse((170, 240, 340, 380), outline="white", width=6)
|
| 34 |
+
draw.ellipse((120, 260, 210, 330), outline="white", width=6)
|
| 35 |
+
draw.ellipse((130, 240, 160, 270), outline="white", width=6)
|
| 36 |
+
draw.ellipse((180, 240, 210, 270), outline="white", width=6)
|
| 37 |
+
draw.line((340, 320, 450, 260), fill="white", width=6)
|
| 38 |
+
draw.ellipse((155, 285, 165, 295), fill="white")
|
| 39 |
+
draw.ellipse((185, 285, 195, 295), fill="white")
|
| 40 |
else:
|
| 41 |
+
draw.text((50, 250), "I can draw only cats & rats", fill="white")
|
| 42 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
draw.rectangle([0, 470, 512, 512], fill=(0, 0, 0))
|
| 44 |
draw.text((10, 472), f"Prompt: {prompt[:30]}", fill="white")
|
| 45 |
|