Spaces:
Runtime error
Runtime error
Add application file
Browse files- app.py +31 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
import openai
|
4 |
+
|
5 |
+
st.title("DALL-E2 API Image Generation Demo")
|
6 |
+
openai.api_key = st.text_input("Enter Your OpenAI Key", "")
|
7 |
+
|
8 |
+
st.write("Enter a prompt to generate an image")
|
9 |
+
|
10 |
+
prompt = st.text_area("Prompt", "An old man wearing a t-shirt with the word 'SMILE' printed.")
|
11 |
+
|
12 |
+
num_images = st.slider("Number of images to generate", min_value=1, max_value=10, value=1)
|
13 |
+
|
14 |
+
image_size = st.selectbox(
|
15 |
+
"Select an image size",
|
16 |
+
["256x256", "512x512", "1024x1024"]
|
17 |
+
)
|
18 |
+
|
19 |
+
def generate_images(prompt, num_images, image_size):
|
20 |
+
response = openai.Image.create(
|
21 |
+
prompt=prompt,
|
22 |
+
n=num_images,
|
23 |
+
size=image_size,
|
24 |
+
)
|
25 |
+
return response["data"]
|
26 |
+
|
27 |
+
if st.button("Generate Images"):
|
28 |
+
with st.spinner("Generating images..."):
|
29 |
+
image_data = generate_images(prompt, num_images, image_size)
|
30 |
+
for idx, image in enumerate(image_data):
|
31 |
+
st.image(image['url'], caption=f"Image {idx+1}", width=400)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
openai
|
3 |
+
tiktoken
|