Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,32 @@
|
|
1 |
import os
|
|
|
2 |
import openai
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# Load
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
openai.api_key = api_key
|
8 |
|
9 |
def generate_image(prompt):
|
10 |
-
response = openai.
|
11 |
-
model="dall-e-3",
|
12 |
prompt=prompt,
|
13 |
-
size="1024x1024",
|
14 |
n=1,
|
|
|
15 |
)
|
16 |
-
return response
|
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()
|
|
|
1 |
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
import openai
|
4 |
import gradio as gr
|
5 |
|
6 |
+
# Load environment variables
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Get the API key from Hugging Face Secrets
|
10 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
11 |
+
|
12 |
+
# Ensure API key is set
|
13 |
+
if not api_key:
|
14 |
+
raise ValueError("OPENAI_API_KEY is not set. Please check your Hugging Face Secrets.")
|
15 |
+
|
16 |
openai.api_key = api_key
|
17 |
|
18 |
def generate_image(prompt):
|
19 |
+
response = openai.Image.create(
|
|
|
20 |
prompt=prompt,
|
|
|
21 |
n=1,
|
22 |
+
size="1024x1024"
|
23 |
)
|
24 |
+
return response["data"][0]["url"]
|
25 |
|
26 |
+
# Create Gradio Interface
|
27 |
gr.Interface(
|
28 |
fn=generate_image,
|
29 |
inputs=gr.Textbox(label="Describe your image"),
|
30 |
outputs=gr.Image(label="Generated Image"),
|
31 |
title="DALL-E Image Generator"
|
32 |
+
).launch()
|