Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,21 @@ import gradio as gr
|
|
3 |
from openai import OpenAI
|
4 |
client = OpenAI(api_key=os.getenv("API_KEY"))
|
5 |
|
6 |
-
def generate_image(prompt, code
|
7 |
if code != os.getenv("code"):
|
8 |
raise gr.Error("❗ Не верный ключ!")
|
9 |
return None
|
10 |
-
size = "256x256" if size_512 else "1024x1024"
|
11 |
response = client.images.generate(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
)
|
17 |
|
18 |
image_url = response.data[0].url
|
19 |
print(image_url)
|
20 |
return image_url
|
21 |
-
|
22 |
css = """
|
23 |
footer {visibility: hidden !important;}
|
24 |
"""
|
@@ -30,12 +29,10 @@ with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
|
|
30 |
code = gr.Textbox(label="Ключ доступа", type="password")
|
31 |
with gr.Row():
|
32 |
prompt_input = gr.Textbox(label="Описание изображения", lines=3)
|
33 |
-
with gr.Row():
|
34 |
-
size_512_checkbox = gr.Checkbox(label="256x256", value=False)
|
35 |
submit_btn = gr.Button("Генерация", variant='primary')
|
36 |
with gr.Column():
|
37 |
image_output = gr.Image(label="Изображение")
|
38 |
|
39 |
-
submit_btn.click(fn=generate_image, inputs=[prompt_input, code
|
40 |
|
41 |
demo.launch()
|
|
|
3 |
from openai import OpenAI
|
4 |
client = OpenAI(api_key=os.getenv("API_KEY"))
|
5 |
|
6 |
+
def generate_image(prompt, code):
|
7 |
if code != os.getenv("code"):
|
8 |
raise gr.Error("❗ Не верный ключ!")
|
9 |
return None
|
|
|
10 |
response = client.images.generate(
|
11 |
+
model="dall-e-3",
|
12 |
+
prompt=prompt,
|
13 |
+
size="1024x1024",
|
14 |
+
quality="hd",
|
15 |
+
n=1,
|
16 |
)
|
17 |
|
18 |
image_url = response.data[0].url
|
19 |
print(image_url)
|
20 |
return image_url
|
|
|
21 |
css = """
|
22 |
footer {visibility: hidden !important;}
|
23 |
"""
|
|
|
29 |
code = gr.Textbox(label="Ключ доступа", type="password")
|
30 |
with gr.Row():
|
31 |
prompt_input = gr.Textbox(label="Описание изображения", lines=3)
|
|
|
|
|
32 |
submit_btn = gr.Button("Генерация", variant='primary')
|
33 |
with gr.Column():
|
34 |
image_output = gr.Image(label="Изображение")
|
35 |
|
36 |
+
submit_btn.click(fn=generate_image, inputs=[prompt_input, code], outputs=image_output)
|
37 |
|
38 |
demo.launch()
|