Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
import os | |
# API ссылка | |
url = "https://stablediffusionapi.com/api/v4/dreambooth" | |
# API ключ | |
api_key = os.getenv("KEY") | |
model_list = ["AbsoluteReality 1.8.1", "Elldreth's Vivid Mix", "Anything V5", "Openjourney V4", "Analog Diffusion", "Lyriel 1.6", "Realistic Vision 5.0", "Dreamshaper 8", "epiCRealism v5", "CyberRealistic 3.3", "ToonYou 6", "Deliberate 3"] | |
# Функция для отправки запроса | |
def render(prompt, model, negative_prompt, width, height, guidance, seed, upscale): | |
data = { | |
"key": api_key, | |
"model_id": model, | |
"prompt": prompt, | |
"negative_prompt": negative_prompt, | |
"width": width, | |
"height": height, | |
"samples": "1", | |
"num_inference_steps": "40", | |
"safety_checker": "no", | |
"enhance_prompt": "yes", | |
"seed": seed, | |
"guidance_scale": guidance, | |
"multi_lingual": "no", | |
"panorama": "no", | |
"self_attention": "no", | |
"upscale": upscale, # Исправлено: передавайте значение upscale | |
"embeddings": "embeddings_model_id", | |
"lora": "lora_model_id", | |
"webhook": None, | |
"track_id": None, | |
} | |
response = requests.post(url, json=data) | |
if response.status_code == 200: | |
return response.content | |
else: | |
return None | |
tab_1 = [ | |
gr.Textbox(render, label="Описание изображения:", placeholder="Введите описание изображения", lines=3), | |
gr.Radio(render, interactive=True, value="Anything V5", show_label=True, label="Модель:", choices=model_list), | |
] | |
tab_2 = [ | |
gr.Textbox(render, label="Negative Prompt:", placeholder="Введите Negative Prompt", value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry", lines=3), | |
gr.Slider(render, show_label=True, minimum=256, maximum=2048, label="Ширина:", value=512, step=1), # Исправлено: передавайте числовые значения | |
gr.Slider(render, show_label=True, minimum=256, maximum=2048, label="Высота:", value=512, step=1), # Исправлено: передавайте числовые значения | |
gr.Slider(render, show_label=True, minimum=1, maximum=20, label="CFG Scale:", value=7.5, step=0.5), # Исправлено: передавайте числовые значения | |
gr.Slider(render, show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1), | |
gr.Dropdown(render, choices=["yes", "no"], label="Upscale", value="no"), | |
] | |
tabs = gr.Tab([tab_1, tab_2], title=["Базовые настройки", "Расширенные настройки"]) | |
# UI | |
gr.Interface( | |
fn=render, | |
inputs=[tabs], # Исправлено: передавайте входные данные как список | |
outputs=gr.Image(), | |
).launch() | |