Spaces:
Running
Running
dhanishetty
commited on
Commit
•
a616b2e
1
Parent(s):
93657f5
Update app.py
Browse files
app.py
CHANGED
@@ -2,26 +2,35 @@ from PIL import Image
|
|
2 |
import requests
|
3 |
from openai import OpenAI
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
-
|
8 |
-
def get_image(prompt,textbox):
|
9 |
-
prompt = prompt
|
10 |
-
client = OpenAI(api_key=textbox)
|
11 |
-
response = client.images.generate(
|
12 |
-
model = "dall-e-3",
|
13 |
-
prompt = prompt,
|
14 |
-
size = "1024x1024",
|
15 |
-
n = 1
|
16 |
-
)
|
17 |
-
image_url = response.data[0].url
|
18 |
-
data = requests.get(image_url).content
|
19 |
-
f = open('img.jpg','wb')
|
20 |
-
f.write(data)
|
21 |
-
f.close()
|
22 |
-
img = Image.open('img.jpg')
|
23 |
-
return img
|
24 |
-
|
25 |
title = "Please Provide API-Key and Enter your Prompt"
|
26 |
description = """
|
27 |
<img src = "https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" width=300px>
|
|
|
2 |
import requests
|
3 |
from openai import OpenAI
|
4 |
import gradio as gr
|
5 |
+
img1 = "img1.png"
|
6 |
+
img3 = "img3.png"
|
7 |
+
|
8 |
+
|
9 |
+
def Get_image(prompt, api_key):
|
10 |
+
if api_key == '':
|
11 |
+
output= img1
|
12 |
+
else:
|
13 |
+
try:
|
14 |
+
client = OpenAI(api_key=api_key)
|
15 |
+
response = client.images.generate(
|
16 |
+
model = "dall-e-3",
|
17 |
+
prompt = prompt,
|
18 |
+
size = "1024x1024",
|
19 |
+
n = 1
|
20 |
+
)
|
21 |
+
image_url = response.data[0].url
|
22 |
+
data = requests.get(image_url).content
|
23 |
+
f = open('img.jpg','wb')
|
24 |
+
f.write(data)
|
25 |
+
f.close()
|
26 |
+
img = Image.open('img.jpg')
|
27 |
+
|
28 |
+
output = img
|
29 |
+
except :
|
30 |
+
output = img3
|
31 |
+
return output
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
title = "Please Provide API-Key and Enter your Prompt"
|
35 |
description = """
|
36 |
<img src = "https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" width=300px>
|