Spaces:
Runtime error
Runtime error
File size: 1,335 Bytes
bbe7ddd de0a6cb bbe7ddd 5db7bfe e04ef84 bbe7ddd de0a6cb dfde0fa bbe7ddd dfde0fa bbe7ddd de0a6cb 8dd67e8 de0a6cb 16108ce de0a6cb 002797e de0a6cb e04ef84 8dd67e8 e04ef84 de0a6cb e04ef84 dfde0fa de0a6cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import os
import requests
import gradio as gr
api_key = os.getenv("API_KEY")
def generate_image(prompt, code):
if code != os.getenv("code"):
raise gr.Error("❗ Не верный ключ!")
return None
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"prompt": prompt,
"num_images": 1,
}
response = requests.post("https://api.openai.com/v1/images/generations", headers=headers, json=data)
response_json = response.json()
# Получаем URL первого сгенерированного изображения
image_url = response_json["data"][0]["url"]
return image_url
css = """
footer {visibility: hidden !important;}
"""
# Создание интерфейса с помощью Gradio
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
with gr.Row():
code = gr.Textbox(label="Ключ доступа", type="password")
with gr.Row():
prompt_input = gr.Textbox(label="Описание изображения")
submit_btn = gr.Button("Генерация", variant='primary')
image_output = gr.Image(label="Изображение")
submit_btn.click(fn=generate_image, inputs=[prompt_input, code], outputs=image_output)
demo.launch() |