Spaces:
Runtime error
Runtime error
Commit
·
887d429
1
Parent(s):
19896a1
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,34 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import openai
|
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
import numpy as np
|
7 |
|
8 |
openai.api_key = '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' # your api key
|
9 |
-
openai.Model.list()
|
10 |
|
11 |
def DALLE(user_input):
|
12 |
prompt = user_input
|
13 |
response = prompt
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
# Convert the
|
22 |
-
img_bytes = io.BytesIO(
|
23 |
img = Image.open(img_bytes)
|
24 |
img_arr = np.array(img)
|
25 |
|
@@ -27,3 +36,4 @@ def DALLE(user_input):
|
|
27 |
|
28 |
iface = gr.Interface(fn=DALLE, inputs="text", outputs="image", title="bhAI")
|
29 |
iface.launch()
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
+
import requests
|
5 |
from PIL import Image
|
6 |
import io
|
7 |
import numpy as np
|
8 |
|
9 |
openai.api_key = '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' # your api key
|
|
|
10 |
|
11 |
def DALLE(user_input):
|
12 |
prompt = user_input
|
13 |
response = prompt
|
14 |
|
15 |
+
# Create the DALL-E image using the OpenAI API
|
16 |
+
data = {
|
17 |
+
"model": "image-alpha-001",
|
18 |
+
"prompt": f"{prompt}:::",
|
19 |
+
"n": 1,
|
20 |
+
"size": "1024x1024",
|
21 |
+
"response_format": "url"
|
22 |
+
}
|
23 |
+
headers = {
|
24 |
+
"Content-Type": "application/json",
|
25 |
+
"Authorization": f"Bearer {openai.api_key}"
|
26 |
+
}
|
27 |
+
response = requests.post("https://api.openai.com/v1/images/generations", json=data, headers=headers)
|
28 |
+
response.raise_for_status()
|
29 |
|
30 |
+
# Convert the image to a format that Gradio can display
|
31 |
+
img_bytes = io.BytesIO(requests.get(response.json()["data"][0]["url"]).content)
|
32 |
img = Image.open(img_bytes)
|
33 |
img_arr = np.array(img)
|
34 |
|
|
|
36 |
|
37 |
iface = gr.Interface(fn=DALLE, inputs="text", outputs="image", title="bhAI")
|
38 |
iface.launch()
|
39 |
+
|