Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
openai.api_key = "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"
|
| 5 |
+
|
| 6 |
+
def generate_image(prompt, model):
|
| 7 |
+
response = openai.Image.create(
|
| 8 |
+
prompt=f"pixel art {prompt}",
|
| 9 |
+
n=1,
|
| 10 |
+
size="256x256",
|
| 11 |
+
model=model,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
if response['status'] != 'completed' or not response['data']:
|
| 15 |
+
raise ValueError("Failed to generate image")
|
| 16 |
+
|
| 17 |
+
return response['data'][0]['url']
|
| 18 |
+
|
| 19 |
+
st.title("Pixel Art Generator")
|
| 20 |
+
|
| 21 |
+
model = "image-alpha-001"
|
| 22 |
+
prompt = st.text_input("Enter your prompt (e.g. dog):")
|
| 23 |
+
|
| 24 |
+
if st.button("Generate Pixel Art"):
|
| 25 |
+
if prompt == "":
|
| 26 |
+
st.warning("Please enter a prompt")
|
| 27 |
+
else:
|
| 28 |
+
try:
|
| 29 |
+
image_url = generate_image(prompt, model)
|
| 30 |
+
st.image(image_url, width=256, caption="Generated Pixel Art")
|
| 31 |
+
except:
|
| 32 |
+
st.error("Failed to generate pixel art. Please try again later.")
|