bonosa commited on
Commit
8cb9766
·
1 Parent(s): bf708f4
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import urllib.request
4
+ from PIL import Image
5
+ import os
6
+ openai.api_key = os.environ['key1']
7
+
8
+ def generate_image(prompt):
9
+ response = openai.Image.create(
10
+ prompt=prompt,
11
+ n=1,
12
+ size="1024x1024"
13
+ )
14
+
15
+ image_url = response['data'][0]['url']
16
+
17
+ # Open the URL image, resize it to 512x512 and return it
18
+ with urllib.request.urlopen(image_url) as url:
19
+ with open('temp.jpg', 'wb') as f:
20
+ f.write(url.read())
21
+ img = Image.open('temp.jpg')
22
+ img = img.resize((512, 512))
23
+
24
+ return img
25
+
26
+ iface = gr.Interface(
27
+ fn=generate_image,
28
+ inputs="text",
29
+ outputs=gr.outputs.Image(type='pil'),
30
+ examples=["a macaw in a hat sitting on a bench in a park"]
31
+ )
32
+
33
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ urllib
2
+ pil