imagegen / app.py
santoshmds21's picture
Create app.py
8ba274f verified
raw
history blame contribute delete
825 Bytes
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}")