Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
|
| 6 |
+
# DALL-E-2 API endpoint
|
| 7 |
+
API_ENDPOINT = "https://api.openai.com/v1/dall-e-generate"
|
| 8 |
+
|
| 9 |
+
st.title("DALL-E-2 Image Generator")
|
| 10 |
+
|
| 11 |
+
# User input text
|
| 12 |
+
user_input = st.text_input("Enter a description for the image:")
|
| 13 |
+
|
| 14 |
+
if st.button("Generate Image"):
|
| 15 |
+
# Make a request to the DALL-E-2 API
|
| 16 |
+
response = requests.post(API_ENDPOINT, json={"text": user_input})
|
| 17 |
+
|
| 18 |
+
# Check if the request was successful
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
# Decode the image from base64 and display it
|
| 21 |
+
image_data = response.json()["image"]
|
| 22 |
+
image = Image.open(BytesIO(image_data))
|
| 23 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
| 24 |
+
else:
|
| 25 |
+
st.error(f"Error generating image. Status code: {response.status_code}")
|