File size: 1,701 Bytes
54e4ef3
 
dfdf1c1
 
 
cb7a4f6
54e4ef3
dfdf1c1
 
54e4ef3
dfdf1c1
302e1e2
 
dfdf1c1
 
4bad760
 
 
ec59411
b33cda6
46f8409
 
 
 
 
cb7a4f6
 
631bc3a
9923b31
 
dfdf1c1
46f8409
 
dfdf1c1
 
2105b98
dfdf1c1
 
2aed1c2
46f8409
cb7a4f6
 
46f8409
69b89c4
fd5c13c
46f8409
dfdf1c1
69b89c4
cb7a4f6
be3ffcc
46f8409
733756a
6f235bb
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
import gradio as gr
import torch
import os
import secrets
from diffusers import StableDiffusionPipeline, LCMScheduler, AutoencoderTiny
from huggingface_hub import hf_hub_download

# Папка для файлов
os.makedirs("outputs", exist_ok=True)

# 1. Загрузка модели
model_path = hf_hub_download(repo_id="zw89/DreamShaper", filename="DreamShaper_8_pruned.safetensors")
pipe = StableDiffusionPipeline.from_single_file(model_path, torch_dtype=torch.float32)

# 2. Ускорители
lora_path = hf_hub_download(repo_id="zw89/lcm-lora-sdv1-5", filename="pytorch_lora_weights.safetensors")
pipe.load_lora_weights(lora_path)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.to("cpu")

# 1. Изменяем функцию, чтобы она принимала ДВА аргумента
def generate(prompt, negative_prompt):
    seed = secrets.randbits(32)
    generator = torch.Generator().manual_seed(seed)
    
    image = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_inference_steps=5,
        guidance_scale=1.0,
        width=512, 
        height=512,
        generator=generator
    ).images[0]
    
    file_path = f"outputs/art_{seed}.png"
    image.save(file_path, "PNG")
    return file_path

# 2. Настраиваем интерфейс с двумя полями
demo = gr.Interface(
    fn=generate, 
    inputs=[
        gr.Textbox(label="Promt"),
        gr.Textbox(label="Negative", value="low quality, plastic, blurry") # Значение по умолчанию
    ],
    outputs=gr.Image(type="filepath", label="PNG"),
    title="SD Mini Dream"
)


demo.launch(server_name="0.0.0.0", server_port=7860)