Furkan12 commited on
Commit
3631e5f
1 Parent(s): a9ad2d4
Files changed (1) hide show
  1. app.py +16 -39
app.py CHANGED
@@ -1,44 +1,21 @@
1
  import gradio as gr
2
- import torch
3
- from PIL import Image
4
- from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
5
 
6
- import gradio as gr
7
-
8
- gr.load("models/radames/stable-diffusion-2-1-img2img").launch()
9
-
10
- model_id = "stabilityai/stable-diffusion-2-1"
11
-
12
- device = "cpu"
13
- # DPM-Solver++ scheduler'ını kullan, torch_dtype belirtme
14
- pipe = StableDiffusionPipeline.from_pretrained(model_id)
15
- pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
16
- pipe = pipe.to(device)
17
 
18
- def resize(value, img_path):
19
- img = Image.open(img_path)
20
- img = img.resize((value, value))
21
- return img
 
 
22
 
23
- def infer(source_img, prompt, negative_prompt, guide, steps, seed, Strength):
24
- generator = torch.Generator(device).manual_seed(seed)
25
- source_image = resize(768, source_img)
26
- source_image.save('source.png')
27
- image = pipe(prompt, negative_prompt=negative_prompt, init_image=source_image, strength=Strength, guidance_scale=guide, num_inference_steps=steps, generator=generator).images[0]
28
- return image
 
29
 
30
- gr.Interface(
31
- fn=infer,
32
- inputs=[
33
- gr.Image(type="filepath", label="Raw Image. Must Be .png"), # Güncellenmiş kullanım
34
- gr.Textbox(label='Prompt Input Text. 77 Token (Keyword or Symbol) Maximum'),
35
- gr.Textbox(label='What you Do Not want the AI to generate.'),
36
- gr.Slider(2, 15, value=7, label='Guidance Scale'),
37
- gr.Slider(1, 25, value=10, step=1, label='Number of Iterations'),
38
- gr.Slider(label="Seed", minimum=0, maximum=987654321987654321, step=1, randomize=True),
39
- gr.Slider(label='Strength', minimum=0, maximum=1, step=.05, value=.5)
40
- ],
41
- outputs=gr.Image(type="pil"),
42
- title="Stable Diffusion 2.1 Image to Image Pipeline on CPU",
43
- description="For more information on Stable Diffusion 2.1 see https://github.com/Stability-AI/stablediffusion"
44
- ).launch()
 
1
  import gradio as gr
 
 
 
2
 
3
+ # Modeli yükle
4
+ model = gr.load("models/radames/stable-diffusion-2-1-img2img")
 
 
 
 
 
 
 
 
 
5
 
6
+ def my_custom_function(image, prompt):
7
+ # Modeli doğrudan çağır
8
+ output = model(image=image, prompt=prompt)
9
+ # Burada output üzerinde ek işlemler yapabilirsiniz
10
+ # Örneğin, çıktıyı yeniden boyutlandırma, filtreleme vb.
11
+ return output
12
 
13
+ iface = gr.Interface(
14
+ fn=my_custom_function,
15
+ inputs=[gr.Image(type="pil"), gr.Textbox()],
16
+ outputs=gr.Image(type="pil"),
17
+ title="My Custom Stable Diffusion img2img Interface",
18
+ description="This is a custom interface for Stable Diffusion img2img model with additional processing."
19
+ )
20
 
21
+ iface.launch()