Spaces:
Sleeping
Sleeping
File size: 1,115 Bytes
6637607 6b2bc5d 6637607 6b2bc5d 6637607 6b2bc5d 6637607 6b2bc5d 6637607 6b2bc5d 6637607 6b2bc5d 6637607 |
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 |
import gradio as gr
from PIL import Image, ImageDraw, ImageFont
# Function to generate a simple image based on description
def generate_image(description):
# Create a blank white canvas of 300x300 pixels
img = Image.new('RGB', (300, 300), color=(255, 255, 255))
# Create an ImageDraw object to add shapes and text
draw = ImageDraw.Draw(img)
# Check for specific keywords in the description
if "circle" in description.lower():
# Draw a blue circle
draw.ellipse([(50, 50), (250, 250)], fill="blue", outline="black")
# Add the description text on the image
font = ImageFont.load_default()
draw.text((60, 260), description, fill="black", font=font)
# Return the generated image
return img
# Create a Gradio interface
interface = gr.Interface(
fn=generate_image,
inputs="text",
outputs="image",
title="Simple Text-to-Image Generator",
description="Enter a description, and the app will generate an image based on it. For example, try 'circle'."
)
# Launch the Gradio app
if __name__ == "__main__":
interface.launch()
|