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()