File size: 1,069 Bytes
5f140c3
 
 
c67f33e
5f140c3
 
 
 
 
 
 
 
 
 
 
 
c67f33e
5f140c3
 
 
 
 
 
d57b22c
5f140c3
c67f33e
5f140c3
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
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()