codermert commited on
Commit
9ef5510
·
verified ·
1 Parent(s): 82cfdb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -4,28 +4,30 @@ import torch
4
  from PIL import Image
5
  import random
6
 
7
- model_id = "stabilityai/stable-diffusion-xl-base-1.0"
8
- lora_model_id = "codermert/tugce2-lora" # Your LoRA model
9
 
10
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
11
  pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
12
- pipe = pipe.to("cuda")
13
  pipe.load_lora_weights(lora_model_id)
 
14
 
15
  def generate_image(prompt, negative_prompt, steps, cfg_scale, seed, strength):
16
  if seed == -1:
17
  seed = random.randint(1, 1000000000)
18
 
19
- generator = torch.Generator("cuda").manual_seed(seed)
20
 
21
- image = pipe(
22
- prompt=prompt,
23
- negative_prompt=negative_prompt,
24
- num_inference_steps=steps,
25
- guidance_scale=cfg_scale,
26
- generator=generator,
27
- cross_attention_kwargs={"scale": strength},
28
- ).images[0]
 
29
 
30
  return image, seed
31
 
@@ -44,15 +46,15 @@ examples = [
44
  ]
45
 
46
  with gr.Blocks(theme='default', css=css) as app:
47
- gr.HTML("<center><h1>Mert Flux LoRA Explorer</h1></center>")
48
  with gr.Column(elem_id="app-container"):
49
  with gr.Row():
50
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2)
51
  negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What to avoid in the image", lines=2)
52
  with gr.Row():
53
  with gr.Column():
54
- steps = gr.Slider(label="Sampling steps", value=30, minimum=10, maximum=100, step=1)
55
- cfg_scale = gr.Slider(label="CFG Scale", value=7.5, minimum=1, maximum=20, step=0.5)
56
  with gr.Column():
57
  strength = gr.Slider(label="LoRA Strength", value=0.75, minimum=0, maximum=1, step=0.01)
58
  seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
 
4
  from PIL import Image
5
  import random
6
 
7
+ model_id = "CompVis/stable-diffusion-v1-4" # Daha hafif bir model
8
+ lora_model_id = "codermert/mert_flux" # Your LoRA model
9
 
10
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
11
  pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
12
+ pipe = pipe.to("cpu") # CPU'ya taşıyoruz
13
  pipe.load_lora_weights(lora_model_id)
14
+ pipe.safety_checker = None # Safety checker'ı devre dışı bırakıyoruz
15
 
16
  def generate_image(prompt, negative_prompt, steps, cfg_scale, seed, strength):
17
  if seed == -1:
18
  seed = random.randint(1, 1000000000)
19
 
20
+ generator = torch.Generator().manual_seed(seed)
21
 
22
+ with torch.no_grad():
23
+ image = pipe(
24
+ prompt=prompt,
25
+ negative_prompt=negative_prompt,
26
+ num_inference_steps=steps,
27
+ guidance_scale=cfg_scale,
28
+ generator=generator,
29
+ cross_attention_kwargs={"scale": strength},
30
+ ).images[0]
31
 
32
  return image, seed
33
 
 
46
  ]
47
 
48
  with gr.Blocks(theme='default', css=css) as app:
49
+ gr.HTML("<center><h1>Mert Flux LoRA Explorer (CPU Version)</h1></center>")
50
  with gr.Column(elem_id="app-container"):
51
  with gr.Row():
52
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2)
53
  negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What to avoid in the image", lines=2)
54
  with gr.Row():
55
  with gr.Column():
56
+ steps = gr.Slider(label="Sampling steps", value=30, minimum=10, maximum=50, step=1)
57
+ cfg_scale = gr.Slider(label="CFG Scale", value=7.5, minimum=1, maximum=15, step=0.5)
58
  with gr.Column():
59
  strength = gr.Slider(label="LoRA Strength", value=0.75, minimum=0, maximum=1, step=0.01)
60
  seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)