Spaces:
Runtime error
Runtime error
add a dal-e version chooser
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ if openai_key == "":
|
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
-
def generate_image(text, pw):
|
| 28 |
# add a conditional to check for a valid password
|
| 29 |
|
| 30 |
if pw != os.getenv("PW"):
|
|
@@ -32,15 +32,13 @@ def generate_image(text, pw):
|
|
| 32 |
raise gr.Error("Invalid password. Please try again.")
|
| 33 |
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
client = OpenAI(api_key=openai_key)
|
| 38 |
|
| 39 |
response = client.images.generate(
|
| 40 |
prompt=text,
|
| 41 |
-
model=
|
| 42 |
quality="standard", # standard or hd
|
| 43 |
-
size="
|
| 44 |
n=1, # Number of images to generate
|
| 45 |
)
|
| 46 |
except Exception as error:
|
|
@@ -58,10 +56,12 @@ with gr.Blocks() as demo:
|
|
| 58 |
text = gr.Textbox(label="What do you want to create?",
|
| 59 |
placeholder="Enter your text and then click on the \"Image Generate\" button, "
|
| 60 |
"or simply press the Enter key.")
|
|
|
|
|
|
|
| 61 |
btn = gr.Button("Generate Image")
|
| 62 |
output_image = gr.Image(label="Image Output")
|
| 63 |
|
| 64 |
-
text.submit(fn=generate_image, inputs=[text,pw], outputs=output_image, api_name="generate_image")
|
| 65 |
-
btn.click(fn=generate_image, inputs=[text,pw], outputs=output_image, api_name=False)
|
| 66 |
|
| 67 |
demo.launch(share=True)
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
+
def generate_image(text, pw, model):
|
| 28 |
# add a conditional to check for a valid password
|
| 29 |
|
| 30 |
if pw != os.getenv("PW"):
|
|
|
|
| 32 |
raise gr.Error("Invalid password. Please try again.")
|
| 33 |
|
| 34 |
try:
|
|
|
|
|
|
|
| 35 |
client = OpenAI(api_key=openai_key)
|
| 36 |
|
| 37 |
response = client.images.generate(
|
| 38 |
prompt=text,
|
| 39 |
+
model=model, # dall-e-2 or dall-e-3
|
| 40 |
quality="standard", # standard or hd
|
| 41 |
+
size="1024x1024", # varies for dalle-2 and dalle-3, see https://openai.com/pricing for resolutions
|
| 42 |
n=1, # Number of images to generate
|
| 43 |
)
|
| 44 |
except Exception as error:
|
|
|
|
| 56 |
text = gr.Textbox(label="What do you want to create?",
|
| 57 |
placeholder="Enter your text and then click on the \"Image Generate\" button, "
|
| 58 |
"or simply press the Enter key.")
|
| 59 |
+
|
| 60 |
+
model = gr.Dropdown(choices=["dall-e-2", "dall-e-3"], label="Model", value="dall-e-3")
|
| 61 |
btn = gr.Button("Generate Image")
|
| 62 |
output_image = gr.Image(label="Image Output")
|
| 63 |
|
| 64 |
+
text.submit(fn=generate_image, inputs=[text,pw,model], outputs=output_image, api_name="generate_image")
|
| 65 |
+
btn.click(fn=generate_image, inputs=[text,pw,model], outputs=output_image, api_name=False)
|
| 66 |
|
| 67 |
demo.launch(share=True)
|