File size: 825 Bytes
8ba274f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import streamlit as st
import requests
from PIL import Image
from io import BytesIO

# DALL-E-2 API endpoint
API_ENDPOINT = "https://api.openai.com/v1/dall-e-generate"

st.title("DALL-E-2 Image Generator")

# User input text
user_input = st.text_input("Enter a description for the image:")

if st.button("Generate Image"):
    # Make a request to the DALL-E-2 API
    response = requests.post(API_ENDPOINT, json={"text": user_input})

    # Check if the request was successful
    if response.status_code == 200:
        # Decode the image from base64 and display it
        image_data = response.json()["image"]
        image = Image.open(BytesIO(image_data))
        st.image(image, caption="Generated Image", use_column_width=True)
    else:
        st.error(f"Error generating image. Status code: {response.status_code}")