import gradio as gr import requests from PIL import Image from io import BytesIO # Define the function that generates the image def generate_image(prompt): response = requests.post("https://api.openai.com/v1/images/generations", json={ "model": "image-alpha-001", "prompt": prompt, "num_images": 4, "size": "1024x1024", "response_format": "url" }, headers={ "Content-Type": "application/json", "Authorization": "Bearer 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" }) response.raise_for_status() image_url = response.json()["data"][0]["url"] image = Image.open(BytesIO(requests.get(image_url).content)) return image iface = gr.Interface( fn=generate_image, inputs=gr.inputs.Textbox(label="Enter Prompt Here"), outputs="image", examples=[ ["a cat sitting on a couch"], ["a robot walking in the park"], ["a tree made of clouds"], ], title="TalkGPT Image Generation", description="Use AI to generate images based on a prompt.", allow_flagging=False, analytics_enabled=True, theme="compact" )