dschandra's picture
Update app.py
6b2bc5d verified
raw
history blame
1.12 kB
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()