Spaces:
Paused
Paused
File size: 4,848 Bytes
c66f90b d845598 c66f90b b1ebe1d c66f90b 571bfa0 fa7e77a ad32167 087fdc1 ad32167 d845598 170d76d 248b3f8 c66f90b 571bfa0 248b3f8 c66f90b d845598 ad32167 d845598 ad32167 f066d25 170d76d c66f90b 6dda42d 248b3f8 6dda42d 248b3f8 6dda42d c66f90b d845598 c66f90b 170d76d 248b3f8 d845598 c66f90b 170d76d 6dda42d 248b3f8 c66f90b 248b3f8 d845598 c66f90b 170d76d c66f90b 248b3f8 c66f90b f066d25 248b3f8 6dda42d 248b3f8 170d76d 369d95b c66f90b 248b3f8 369d95b c66f90b f066d25 d845598 c66f90b 248b3f8 c66f90b 1d5f68d 65572dd b3d2790 515dc44 65572dd 515dc44 b3d2790 248b3f8 b3d2790 515dc44 65572dd d845598 248b3f8 d845598 4fdc62e 515dc44 1d5f68d 248b3f8 e5e829a |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
import gradio as gr
import numpy as np
import random
import spaces
from diffusers import DiffusionPipeline
import torch
# Подключение к устройству
device = "cuda" if torch.cuda.is_available() else "cpu"
model_repo_id = "stabilityai/stable-diffusion-3-medium-diffusers"
if torch.cuda.is_available():
torch_dtype = torch.bfloat16
else:
torch_dtype = torch.float32
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
pipe = pipe.to(device)
MAX_IMAGE_SIZE = 1024
examples = [
"A stylized 3D Kazakh-themed panda dressed in a colorful chapan with simple gold and turquoise patterns. The panda wears a small tyubeteika hat and holds a dombra in one paw, sitting in a cute and relaxed pose. The design is minimalistic, with smooth textures and a focus on soft shapes and earthy tones.",
"A stylized 3D anthropomorphic bear character with a muscular build, dressed in simple yet rugged armor made of leather and metal. The character wields a large axe with intricate carvings on the blade. The colors are muted with earthy greens and browns, complemented by silver armor accents. Shadows emphasize the character's strength and bold pose, perfect for a medieval fantasy setting.",
"A detailed 3D model of a traditional Kazakh yurt with intricate gold and turquoise ornamentation along the fabric and wooden framework. The yurt is adorned with a fur-lined entrance and traditional steppe patterns on the walls and roof. The structure is surrounded by simple props like a traditional wooden saddle and a dombra, giving a sense of nomadic life.",
]
@spaces.GPU(duration=30)
def infer(
prompt,
width=1024,
height=1024,
num_inference_steps=20,
guidance_scale=7.5,
):
# Генерация изображения
image = pipe(
prompt=prompt,
num_inference_steps=num_inference_steps,
guidance_scale=guidance_scale,
width=width,
height=height,
).images[0]
return image
class CustomTheme(gr.themes.Base):
def __init__(self):
super().__init__()
self.primary_hue = "#191a1e"
self.background_fill_primary = "#191a1e"
self.background_fill_secondary = "#191a1e"
self.background_fill_tertiary = "#191a1e"
self.text_color_primary = "#FFFFFF"
self.text_color_secondary = "#FFFFFF"
self.text_color_tertiary = "#FFFFFF"
self.input_background_fill = "#191a1e"
self.input_text_color = "#FFFFFF"
css = """
/* Скрываем нижний колонтитул */
footer {
visibility: hidden;
height: 0;
margin: 0;
padding: 0;
overflow: hidden;
}
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
/* Применяем шрифты */
body, input, button, textarea, select, .gr-button {
font-family: 'Poppins', sans-serif;
background-color: #191a1e !important;
color: #FFFFFF;
}
/* Настройки заголовков */
h1, h2, h3, h4, h5, h6 {
font-family: 'Poppins', sans-serif;
font-weight: 700;
color: #FFFFFF;
}
/* Стиль для текстовых полей и кнопок */
input[type="text"], textarea {
background-color: #191a1e !important;
color: #FFFFFF;
border: 1px solid #FFFFFF;
}
/* Цвет кнопки Generate */
.generate-button {
background-color: #5271FF !important;
color: #FFFFFF !important;
border: none;
font-weight: bold;
}
.generate-button:hover {
background-color: #405BBF !important; /* Цвет при наведении */
}
/* Выделяем текст для Prompt */
.prompt-text {
font-weight: bold;
color: #FFFFFF;
}
"""
with gr.Blocks(theme=CustomTheme(), css=css) as demo:
with gr.Column(elem_id="col-container"):
gr.Markdown("**Prompt**", elem_classes="prompt-text")
with gr.Row():
prompt = gr.Text(
label="Prompt",
show_label=False,
max_lines=1,
placeholder="Enter your prompt",
container=False,
)
run_button = gr.Button(
"Generate",
scale=0,
variant="primary",
elem_classes="generate-button",
)
result = gr.Image(label="Result", show_label=False)
gr.Examples(
examples=examples,
inputs=[prompt],
outputs=[result],
fn=infer,
cache_examples=True,
cache_mode="lazy",
)
run_button.click(
fn=infer,
inputs=[prompt],
outputs=[result],
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
show_api=False,
)
|