import gradio as gr from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler import torch from PIL import Image import random model_id = "CompVis/stable-diffusion-v1-4" # Daha hafif bir model lora_model_id = "codermert/mert_flux" # Your LoRA model pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32) pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe = pipe.to("cpu") # CPU'ya taşıyoruz pipe.load_lora_weights(lora_model_id) pipe.safety_checker = None # Safety checker'ı devre dışı bırakıyoruz def generate_image(prompt, negative_prompt, steps, cfg_scale, seed, strength): if seed == -1: seed = random.randint(1, 1000000000) generator = torch.Generator().manual_seed(seed) with torch.no_grad(): image = pipe( prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=cfg_scale, generator=generator, cross_attention_kwargs={"scale": strength}, ).images[0] return image, seed css = """ #app-container { max-width: 800px; margin-left: auto; margin-right: auto; } """ examples = [ ["A beautiful landscape with mountains and a lake", "ugly, deformed"], ["A futuristic cityscape at night", "daytime, rural"], ["A portrait of a smiling person in a colorful outfit", "monochrome, frowning"], ] with gr.Blocks(theme='default', css=css) as app: gr.HTML("