Spaces:
Build error
Build error
Rename gradio_dalle.py to app.py
Browse files- gradio_dalle.py → app.py +5 -7
gradio_dalle.py → app.py
RENAMED
|
@@ -1,25 +1,23 @@
|
|
| 1 |
import os
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
-
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def generate_image(prompt):
|
| 9 |
response = openai.images.generate(
|
| 10 |
model="dall-e-3",
|
| 11 |
prompt=prompt,
|
| 12 |
size="1024x1024",
|
| 13 |
-
quality="standard",
|
| 14 |
n=1,
|
| 15 |
)
|
| 16 |
return response.data[0].url
|
| 17 |
|
| 18 |
-
|
| 19 |
fn=generate_image,
|
| 20 |
inputs=gr.Textbox(label="Describe your image"),
|
| 21 |
outputs=gr.Image(label="Generated Image"),
|
| 22 |
title="DALL-E Image Generator"
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
app.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
+
# Load API key from Hugging Face Secrets (not .env)
|
| 6 |
+
api_key = os.environ.get("OPENAI_API_KEY")
|
| 7 |
+
openai.api_key = api_key
|
| 8 |
|
| 9 |
def generate_image(prompt):
|
| 10 |
response = openai.images.generate(
|
| 11 |
model="dall-e-3",
|
| 12 |
prompt=prompt,
|
| 13 |
size="1024x1024",
|
|
|
|
| 14 |
n=1,
|
| 15 |
)
|
| 16 |
return response.data[0].url
|
| 17 |
|
| 18 |
+
gr.Interface(
|
| 19 |
fn=generate_image,
|
| 20 |
inputs=gr.Textbox(label="Describe your image"),
|
| 21 |
outputs=gr.Image(label="Generated Image"),
|
| 22 |
title="DALL-E Image Generator"
|
| 23 |
+
).launch()
|
|
|
|
|
|