Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
from openai import OpenAI
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
|
| 11 |
-
def get_image(prompt
|
| 12 |
response = client.images.generate(
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import requests
|
|
|
|
| 3 |
from openai import OpenAI
|
| 4 |
+
import gradio as gr
|
| 5 |
+
client = OpenAI(api_key= "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")
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
+
def get_image(prompt):
|
| 9 |
response = client.images.generate(
|
| 10 |
+
model = "dall-e-3",
|
| 11 |
+
prompt = prompt,
|
| 12 |
+
size = "1024x1024",
|
| 13 |
+
n = 1
|
| 14 |
+
)
|
| 15 |
+
image_url = response.data[0].url
|
| 16 |
+
data = requests.get(image_url).content
|
| 17 |
+
f = open('img.jpg','wb')
|
| 18 |
+
f.write(data)
|
| 19 |
+
f.close()
|
| 20 |
+
img = Image.open('img.jpg')
|
| 21 |
+
return img
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
gr.Interface(fn=get_image,inputs = "textbox", outputs= gr.Image(type='pil')).launch()
|
| 26 |
|
| 27 |
|