bonosa commited on
Commit
62ddc7e
·
1 Parent(s): 2c9f65b
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -6,7 +6,7 @@ import os
6
  import nltk
7
  #nltk.download('punkt')
8
 
9
- def generate_image(api_key, prompt):
10
  if not api_key:
11
  print("Error: API Key is required.")
12
  return
@@ -14,12 +14,12 @@ def generate_image(api_key, prompt):
14
  response = openai.Image.create(
15
  prompt=prompt,
16
  n=1,
17
- size="256x256"
18
  )
19
 
20
  image_url = response['data'][0]['url']
21
 
22
- # Open the URL image, resize it to 512x512 and return it
23
  with urllib.request.urlopen(image_url) as url:
24
  with open('temp.jpg', 'wb') as f:
25
  f.write(url.read())
@@ -31,11 +31,12 @@ iface = gr.Interface(
31
  fn=generate_image,
32
  inputs=[
33
  gr.inputs.Textbox(lines=1, label="API Key", type="password"),
34
- gr.inputs.Textbox(lines=1, label="Prompt")
 
35
  ],
36
  outputs=gr.outputs.Image(type="pil"),
37
  title="DALL-E Image Generator",
38
- description="Enter your API key and a prompt to generate an image from DALL-E."
39
  )
40
 
41
 
 
6
  import nltk
7
  #nltk.download('punkt')
8
 
9
+ def generate_image(api_key, prompt, resolution):
10
  if not api_key:
11
  print("Error: API Key is required.")
12
  return
 
14
  response = openai.Image.create(
15
  prompt=prompt,
16
  n=1,
17
+ size=resolution
18
  )
19
 
20
  image_url = response['data'][0]['url']
21
 
22
+ # Open the URL image, resize it to the chosen resolution and return it
23
  with urllib.request.urlopen(image_url) as url:
24
  with open('temp.jpg', 'wb') as f:
25
  f.write(url.read())
 
31
  fn=generate_image,
32
  inputs=[
33
  gr.inputs.Textbox(lines=1, label="API Key", type="password"),
34
+ gr.inputs.Textbox(lines=1, label="Prompt"),
35
+ gr.inputs.Radio(choices=["256x256", "512x512", "1024x1024"], label="Resolution")
36
  ],
37
  outputs=gr.outputs.Image(type="pil"),
38
  title="DALL-E Image Generator",
39
+ description="Enter your API key, a prompt, and choose a resolution to generate an image from DALL-E."
40
  )
41
 
42