Spaces:
Runtime error
Runtime error
import streamlit as st | |
import openai | |
openai.api_key ="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 | |
st.title("DALL-E 2 API Image Generation Demo with OpenAI SDK") | |
st.write("Enter a prompt to generate an image") | |
prompt = st.text_area("Prompt", "An eco-friendly computer from the 90s in the style of vaporwave") | |
num_images = st.slider("Number of images to generate", min_value=1, max_value=10, value=1) | |
image_size = st.selectbox( | |
"Select an image size", | |
["256x256", "512x512", "1024x1024"] | |
) | |
def generate_images(prompt, num_images, image_size): | |
response = openai.Image.create( | |
prompt=prompt, | |
n=num_images, | |
size=image_size, | |
) | |
return response["data"] | |
if st.button("Generate Images"): | |
with st.spinner("Generating images..."): | |
image_data = generate_images(prompt, num_images, image_size) | |
for idx, image in enumerate(image_data): | |
st.image(image['url'], caption=f"Image {idx+1}", width=400) | |