nsultan5's picture
Rename gradio_dalle.py to app.py
82965e9 verified
raw
history blame
541 Bytes
import os
import openai
import gradio as gr
# Load API key from Hugging Face Secrets (not .env)
api_key = os.environ.get("OPENAI_API_KEY")
openai.api_key = api_key
def generate_image(prompt):
response = openai.images.generate(
model="dall-e-3",
prompt=prompt,
size="1024x1024",
n=1,
)
return response.data[0].url
gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="Describe your image"),
outputs=gr.Image(label="Generated Image"),
title="DALL-E Image Generator"
).launch()