Spaces:
Runtime error
Runtime error
import os | |
import gradio as gr | |
from openai import OpenAI | |
client = OpenAI(api_key=os.getenv("API_KEY")) | |
def generate_image(prompt, code): | |
if code != os.getenv("code"): | |
raise gr.Error("❗ Не верный ключ!") | |
return None | |
response = client.images.generate( | |
model="dall-e-3", | |
prompt=prompt, | |
size="1024x1024", | |
quality="hd", | |
n=1, | |
) | |
image_url = response.data[0].url | |
print(image_url) | |
return image_url | |
css = """ | |
footer {visibility: hidden !important;} | |
""" | |
# Создание интерфейса с помощью Gradio | |
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo: | |
with gr.Row(): | |
with gr.Column(): | |
with gr.Row(): | |
code = gr.Textbox(label="Ключ доступа", type="password") | |
with gr.Row(): | |
prompt_input = gr.Textbox(label="Описание изображения", lines=3) | |
submit_btn = gr.Button("Генерация", variant='primary') | |
with gr.Column(): | |
image_output = gr.Image(label="Изображение") | |
submit_btn.click(fn=generate_image, inputs=[prompt_input, code], outputs=image_output) | |
demo.launch() |