Sean Laurent
commited on
Commit
·
43098ef
1
Parent(s):
f88f6dc
Switched to Access Tokens
Browse files
app.py
CHANGED
|
@@ -4,25 +4,27 @@ import os
|
|
| 4 |
|
| 5 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
def open_ai_txt2img(prompt):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Gradio Interface
|
| 17 |
def generator(prompt):
|
| 18 |
-
return open_ai_txt2img(prompt)
|
| 19 |
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
prompt = gr.Textbox(label="Prompt")
|
| 22 |
submit = gr.Button(label="Generate")
|
| 23 |
-
image1 = gr.Image()
|
| 24 |
-
image2 = gr.Image()
|
| 25 |
-
image3 = gr.Image()
|
| 26 |
submit.click(generator, inputs=[prompt], outputs=[image1, image2, image3], api_name="mmd")
|
| 27 |
|
| 28 |
# demo = gr.Interface(fn=generator, inputs="text", outputs="image")
|
|
|
|
| 4 |
|
| 5 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 6 |
|
| 7 |
+
# Generate an image from text using DALL-E
|
| 8 |
def open_ai_txt2img(prompt):
|
| 9 |
+
try:
|
| 10 |
+
response = openai.Image.create(
|
| 11 |
+
prompt=prompt,
|
| 12 |
+
n=3,
|
| 13 |
+
size="1024x1024",
|
| 14 |
+
)
|
| 15 |
+
return [img["url"] for img in response["data"]]
|
| 16 |
+
except openai.error.OpenAIError as e:
|
| 17 |
+
print(e.http_status)
|
| 18 |
+
print(e.error)
|
| 19 |
|
| 20 |
# Gradio Interface
|
| 21 |
def generator(prompt):
|
| 22 |
+
return open_ai_txt2img(prompt)
|
| 23 |
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
prompt = gr.Textbox(label="Prompt")
|
| 26 |
submit = gr.Button(label="Generate")
|
| 27 |
+
image1, image2, image3 = gr.Image(), gr.Image(), gr.Image()
|
|
|
|
|
|
|
| 28 |
submit.click(generator, inputs=[prompt], outputs=[image1, image2, image3], api_name="mmd")
|
| 29 |
|
| 30 |
# demo = gr.Interface(fn=generator, inputs="text", outputs="image")
|