Spaces:
Runtime error
Runtime error
Commit
•
abdc0bd
1
Parent(s):
1399ae0
Update app.py
Browse files
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 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
)
|
|
|
|
|
30 |
|
31 |
-
demo.launch(
|
|
|
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()
|