Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image, ImageDraw, ImageFont | |
def greet(name): | |
# Create an image with a blue background | |
img = Image.new('RGB', (500, 300), color=(100, 150, 255)) | |
# Initialize the drawing context with the image object | |
draw = ImageDraw.Draw(img) | |
# Use the default font provided by PIL | |
font = ImageFont.load_default() | |
# Define the text to be added to the image | |
text = f"Hello {name}!!" | |
# Calculate the size of the text to center it | |
text_width, text_height = draw.textsize(text, font=font) | |
# Calculate the x, y position of the text to be centered | |
x = (img.width - text_width) // 2 | |
y = (img.height - text_height) // 2 | |
# Draw the text on the image | |
draw.text((x, y), text, fill=(255, 255, 255), font=font) # White text color | |
return img | |
# Set up the Gradio interface | |
demo = gr.Interface(fn=greet, inputs="text", outputs="image") | |
# Launch the app | |
demo.launch() | |