Furkan12 commited on
Commit
4938098
·
verified ·
1 Parent(s): 9d6a6a8
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -1,44 +1,32 @@
1
  import gradio as gr
2
- import pandas as pd
3
  import torch
4
- import numpy as np
5
  from PIL import Image
6
- from diffusers import DiffusionPipeline
7
- from huggingface_hub import login
8
- import gradio as gr
9
- import torch
10
- import numpy as np
11
- from PIL import Image
12
- from datasets import load_dataset
13
- from diffusers import StableDiffusionImg2ImgPipeline
14
-
15
- import torch
16
  from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
17
 
18
  model_id = "stabilityai/stable-diffusion-2-1"
19
 
20
  device = "cpu"
21
  # DPM-Solver++ scheduler'ını kullan, torch_dtype belirtme
22
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
23
  pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
24
  pipe = pipe.to(device)
25
 
26
- def resize(value,img):
27
- img = Image.open(img)
28
- img = img.resize((value,value))
29
  return img
30
 
31
  def infer(source_img, prompt, negative_prompt, guide, steps, seed, Strength):
32
- generator = torch.Generator(device).manual_seed(seed)
33
  source_image = resize(768, source_img)
34
  source_image.save('source.png')
35
- image = pipe(prompt, negative_prompt=negative_prompt, init_image=source_image, strength=Strength, guidance_scale=guide, num_inference_steps=steps).images[0]
36
  return image
37
-
38
  gr.Interface(
39
  fn=infer,
40
  inputs=[
41
- gr.inputs.Image(type="filepath", label="Raw Image. Must Be .png"), # Güncellenmiş kullanım
42
  gr.Textbox(label='Prompt Input Text. 77 Token (Keyword or Symbol) Maximum'),
43
  gr.Textbox(label='What you Do Not want the AI to generate.'),
44
  gr.Slider(2, 15, value=7, label='Guidance Scale'),
@@ -46,7 +34,7 @@ gr.Interface(
46
  gr.Slider(label="Seed", minimum=0, maximum=987654321987654321, step=1, randomize=True),
47
  gr.Slider(label='Strength', minimum=0, maximum=1, step=.05, value=.5)
48
  ],
49
- outputs='image',
50
- title="Stable Diffusion 2.1 Image to Image Pipeline on CPU",
51
  description="For more information on Stable Diffusion 2.1 see https://github.com/Stability-AI/stablediffusion"
52
- ).launch()
 
1
  import gradio as gr
 
2
  import torch
 
3
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
4
  from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
5
 
6
  model_id = "stabilityai/stable-diffusion-2-1"
7
 
8
  device = "cpu"
9
  # DPM-Solver++ scheduler'ını kullan, torch_dtype belirtme
10
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
11
  pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
12
  pipe = pipe.to(device)
13
 
14
+ def resize(value, img_path):
15
+ img = Image.open(img_path)
16
+ img = img.resize((value, value))
17
  return img
18
 
19
  def infer(source_img, prompt, negative_prompt, guide, steps, seed, Strength):
20
+ generator = torch.Generator(device).manual_seed(seed)
21
  source_image = resize(768, source_img)
22
  source_image.save('source.png')
23
+ image = pipe(prompt, negative_prompt=negative_prompt, init_image=source_image, strength=Strength, guidance_scale=guide, num_inference_steps=steps, generator=generator).images[0]
24
  return image
25
+
26
  gr.Interface(
27
  fn=infer,
28
  inputs=[
29
+ gr.Image(type="filepath", label="Raw Image. Must Be .png"), # Güncellenmiş kullanım
30
  gr.Textbox(label='Prompt Input Text. 77 Token (Keyword or Symbol) Maximum'),
31
  gr.Textbox(label='What you Do Not want the AI to generate.'),
32
  gr.Slider(2, 15, value=7, label='Guidance Scale'),
 
34
  gr.Slider(label="Seed", minimum=0, maximum=987654321987654321, step=1, randomize=True),
35
  gr.Slider(label='Strength', minimum=0, maximum=1, step=.05, value=.5)
36
  ],
37
+ outputs=gr.Image(type="pil"),
38
+ title="Stable Diffusion 2.1 Image to Image Pipeline on CPU",
39
  description="For more information on Stable Diffusion 2.1 see https://github.com/Stability-AI/stablediffusion"
40
+ ).launch()