from PIL import Image, ImageDraw, ImageFont import gradio as gr import requests def generate_image(input_text): # Fetch a random quote from the Quote API response = requests.get("https://api.quotable.io/random") quote = response.json()['content'] # Create an image with the quote and input text img = Image.new('RGB', (500, 300), color=(255, 255, 255)) d = ImageDraw.Draw(img) font = ImageFont.truetype("arial.ttf", 24) d.text((10, 10), quote, font=font, fill=(0, 0, 0)) d.text((10, 200), f"You entered: {input_text}", font=font, fill=(0, 0, 0)) return img # Define the Gradio interface iface = gr.Interface( fn=generate_image, inputs=gr.inputs.Textbox(placeholder="Enter text here..."), outputs=gr.outputs.Image(label="Generated Image"), title="Creative Image Generator", description="Generate a creative image with a quote using any input text.", theme="default", layout="vertical", allow_flagging=False ) # Launch the Gradio interface iface.launch()