File size: 1,207 Bytes
ebcea15
 
 
 
 
 
 
 
 
abdc0bd
 
 
ebcea15
 
 
 
 
 
 
abdc0bd
 
 
 
 
 
 
 
 
 
 
 
 
 
ebcea15
abdc0bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
import os
import openai

openai.organization = os.getenv("API_ORG")
openai.api_key = os.getenv("API_KEY")
app_password = os.getenv("APP_PASSWORD")
app_username = os.getenv("APP_USERNAME")

def generate(prompt, api_key, api_organization=None):
    openai.organization = api_organization
    openai.api_key = api_key
    response = openai.Image.create(
      prompt=prompt,
      n=1,
      size="256x256"
    )
    return response['data'][0]['url']

with gr.Blocks() as demo:
    gr.Markdown("Demo-app for image generation using DALL-E")
    with gr.Accordion("OpenAI API Settings", open=False):
        api_key = gr.Textbox(label="OpenAI API key", placeholder="OpenAI API key")
        api_organization = gr.Textbox(label="OpenAI API organization", placeholder="OpenAI API organization (optional)")
    with gr.Row():
        inp = gr.Textbox(line=5, label="Input", placeholder="Image prompt")
        out = gr.Image(type="filepath", label="Output")
    examples = gr.Examples(
        [["きのこの山"], ["たけのこの里"]],
        [inp],
    )
    btn = gr.Button("Generate Image")
    btn.click(fn=generate, inputs=[inp, api_key, api_organization], outputs=out)

demo.launch()