Spaces:
Sleeping
Sleeping
File size: 1,800 Bytes
6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 6204463 3774a42 | 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 torch
from diffusers import StableDiffusionPipeline
# 1. Настройка модели
model_id = "Kolyadual/MicroMacro-GenImage-v1-tiny"
# Убираем use_safetensors=True, так как в репозитории их нет
# Добавляем low_cpu_mem_usage для стабильности на бесплатных тарифах
pipe = StableDiffusionPipeline.from_pretrained(
model_id,
torch_dtype=torch.float32,
use_safetensors=False,
low_cpu_mem_usage=True
)
pipe.to("cpu")
# Оптимизация для CPU
pipe.enable_attention_slicing()
def generate(prompt, steps, guidance):
# Генерация
image = pipe(
prompt=prompt,
num_inference_steps=int(steps),
guidance_scale=float(guidance)
).images[0]
return image
# 2. Интерфейс Gradio
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🧪 MicroMacro GenImage v1 Tiny")
gr.Markdown("### Optimized for CPU. Please use **English** prompts.")
with gr.Row():
with gr.Column():
prompt = gr.Textbox(label="Prompt (EN)", placeholder="Alchemy crystal...")
steps = gr.Slider(1, 25, 12, step=1, label="Steps")
guidance = gr.Slider(1, 15, 7.5, step=0.5, label="Guidance Scale")
btn = gr.Button("Generate ✨")
with gr.Column():
output_img = gr.Image(label="Result")
# Примеры для быстрой проверки пользователями
gr.Examples(
examples=[["mystical potion, alchemy style, glowing", 12, 7.5]],
inputs=[prompt, steps, guidance]
)
btn.click(fn=generate, inputs=[prompt, steps, guidance], outputs=output_img)
if __name__ == "__main__":
demo.launch()
|