import openai import gradio as gr from PIL import Image import requests output= gr.Image() def generateImage(prompt): response = openai.images.generate( model="dall-e-3", prompt=prompt, size="1024x1024", quality="standard", n=1, ) return response.data[0].url def handlePrompt(who, doing): prompt = f"{who} {doing}" print("Prompt:", prompt) try: url = generateImage(prompt) if url: image = Image.open(requests.get(url, stream=True).raw) return image except Exception as e: print("Error loading image:", e) # Fallback image if something goes wrong return Image.open("images/ug_logo.jpg") with gr.Blocks() as demo: gr.Image(value="images/ug_logo.jpg", height=200, width=200) gr.HTML("

Unified Ground Image Generator

") gr.HTML("

Welcome to the People of Color in Climate Image Generator

") gr.HTML("

Please send any comments or images you like to jamil@unifiedground.com or tag @brooklyndadshow

") gr.HTML("

I want to see:

") who = gr.Radio( label="Who", choices=[ "People of Color", "Black People", "Latino People", "Indigenous People", "Asian and Pacific Islander People" ], value="People of Color" ) doing = gr.Radio( label="Action", choices=[ "in Climate Jobs", "installing Solar and Battery Storage", "working in Off Shore Wind", "installing a heat pump" ], value="in Climate Jobs" ) generate_btn = gr.Button("Generate Image") output_image = gr.Image(value="images/ug_logo.jpg", height=1024, width=1024, type="pil") generate_btn.click(fn=handlePrompt, inputs=[who, doing], outputs=output_image) demo.launch()