File size: 1,732 Bytes
645a646
 
bdc1000
f3e26fa
 
645a646
 
76109aa
65b9940
645a646
 
76109aa
645a646
76109aa
 
406fedb
 
76109aa
 
406fedb
76109aa
406fedb
 
 
 
 
 
 
 
 
 
 
 
645a646
fae13e8
645a646
 
f3e26fa
645a646
 
 
 
dd7838a
 
 
a30ee48
 
 
76109aa
 
 
 
dd7838a
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import requests
import os
import io
from PIL import Image

# API ссылка
url = "https://api-inference.huggingface.co/models/stablediffusionapi/realistic-vision-51"


# Функция для отправки запроса
def render(prompt, negative_prompt, output_format, width, height, upscale, api_key):
    data = {
        "key":  api_key,  
        "model_id": "realistic-vision-51",  
        "prompt": prompt, 
        "negative_prompt": negative_prompt,  
        "width":  width,  
        "height":  height,  
        "samples":  "1",  
        "num_inference_steps":  "40",  
        "safety_checker":  "no",  
        "enhance_prompt":  "yes",  
        "seed":  None,  
        "guidance_scale":  7.5,  
        "multi_lingual":  "no",  
        "panorama":  "no",  
        "self_attention":  "no",  
        "upscale":  "no",  
        "embeddings":  "embeddings_model_id",  
        "lora":  "lora_model_id",  
        "webhook":  None,  
        "track_id":  None,
    }
    response = requests.post(url, headers=headers, json=data)
    if response.status_code == 200:
        return response.content
        image = Image.open(io.BytesIO(response.content))
    else:
        return None

# UI
gr.Interface(
    render,
    inputs=[
        gr.Textbox(placeholder="Введите описание изображения"),
        gr.Textbox(placeholder="Введите отрицательный образ"),
        gr.Dropdown(["png", "jpg", "webp", "gif"]),
        gr.Dropdown(["256", "512", "1024", "2048"]),
        gr.Dropdown(["256", "512", "1024", "2048"]),
        gr.Dropdown(["yes", "no"]),
        gr.Textbox(placeholder="API_KEY"),
    ],
    outputs=gr.Image()
).launch()