dovedovepigeon commited on
Commit
abdc0bd
1 Parent(s): 1399ae0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -7,7 +7,9 @@ openai.api_key = os.getenv("API_KEY")
7
  app_password = os.getenv("APP_PASSWORD")
8
  app_username = os.getenv("APP_USERNAME")
9
 
10
- def generate(prompt):
 
 
11
  response = openai.Image.create(
12
  prompt=prompt,
13
  n=1,
@@ -15,17 +17,19 @@ def generate(prompt):
15
  )
16
  return response['data'][0]['url']
17
 
18
- examples = [
19
- ["きのこの山"],
20
- ["たけのこの里"],
21
- ]
22
-
23
- demo = gr.Interface(
24
- fn=generate,
25
- inputs=gr.components.Textbox(lines=5, label="Prompt"),
26
- outputs=gr.components.Image(type="filepath", label="Generated Image"),
27
- flagging_options=[],
28
- examples=examples
29
- )
 
 
30
 
31
- demo.launch(share=False, auth=(app_username, app_password))
 
7
  app_password = os.getenv("APP_PASSWORD")
8
  app_username = os.getenv("APP_USERNAME")
9
 
10
+ def generate(prompt, api_key, api_organization=None):
11
+ openai.organization = api_organization
12
+ openai.api_key = api_key
13
  response = openai.Image.create(
14
  prompt=prompt,
15
  n=1,
 
17
  )
18
  return response['data'][0]['url']
19
 
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("Demo-app for image generation using DALL-E")
22
+ with gr.Accordion("OpenAI API Settings", open=False):
23
+ api_key = gr.Textbox(label="OpenAI API key", placeholder="OpenAI API key")
24
+ api_organization = gr.Textbox(label="OpenAI API organization", placeholder="OpenAI API organization (optional)")
25
+ with gr.Row():
26
+ inp = gr.Textbox(line=5, label="Input", placeholder="Image prompt")
27
+ out = gr.Image(type="filepath", label="Output")
28
+ examples = gr.Examples(
29
+ [["きのこの山"], ["たけのこの里"]],
30
+ [inp],
31
+ )
32
+ btn = gr.Button("Generate Image")
33
+ btn.click(fn=generate, inputs=[inp, api_key, api_organization], outputs=out)
34
 
35
+ demo.launch()