|
import gradio as gr |
|
import os |
|
import requests |
|
|
|
def generate_image(prompt, auth_key): |
|
headers = { |
|
"Authorization": f"Bearer {auth_key}", |
|
"Content-Type": "application/json" |
|
} |
|
data = { |
|
"description": prompt |
|
} |
|
response = requests.post("http://localhost:5000/generate-image", json=data, headers=headers) |
|
if response.status_code != 200: |
|
raise gr.Error(f"Ошибка при генерации изображения: {response.json().get('error')}") |
|
return response.json()['image_url'] |
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
prompt_input = gr.Textbox(label="Описание изображения", lines=2) |
|
auth_input = gr.Textbox(label="Ключ авторизации", type="password") |
|
submit_button = gr.Button("Сгенерировать изображение") |
|
image_output = gr.Image(label="Сгенерированное изображение") |
|
|
|
submit_button.click(fn=generate_image, inputs=[prompt_input, auth_input], outputs=image_output) |
|
|
|
demo.launch() |