Spaces:
Sleeping
Sleeping
Download app.py from unifiedGround/POCClimateImages: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/unifiedGround/POCClimateImages/resolve/main/app.py
- Command line
-
hf download hf://spaces/unifiedGround/POCClimateImages/app.py
-
curl -L -o app.py https://huggingface.co/spaces/unifiedGround/POCClimateImages/resolve/main/app.py
1.89 kB
| 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("<h1>Unified Ground Image Generator</h1>") | |
| gr.HTML("<p>Welcome to the People of Color in Climate Image Generator</p>") | |
| gr.HTML("<p>Please send any comments or images you like to jamil@unifiedground.com or tag @brooklyndadshow</p>") | |
| gr.HTML("<p>I want to see:</p>") | |
| 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() |