Furkan12 commited on
Commit
daf62cf
1 Parent(s): 3631e5f
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -1,21 +1,28 @@
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()
 
 
 
 
 
 
1
  import gradio as gr
2
+ from diffusers import StableDiffusionImg2ImgPipeline
3
+ import torch
4
+ from PIL import Image
5
 
6
+ # Modelinizi yükleyin
7
+ model_id = "radames/stable-diffusion-2-1-img2img"
8
+ device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
+ pipeline = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, use_auth_token=True).to(device)
 
 
 
 
 
11
 
12
+ def generate_image(img, prompt):
13
+ # Görüntüyü PIL Image olarak açın ve boyutunu değiştirin (isteğe bağlı)
14
+ image = img.resize((512, 512))
15
+
16
+ # Modeli çağırarak görüntüyü üretin
17
+ with torch.no_grad():
18
+ output_image = pipeline(prompt=prompt, init_image=image, strength=0.75, guidance_scale=7.5)["sample"][0]
19
+
20
+ # Çıktıyı PIL Image olarak döndürün
21
+ return output_image
22
 
23
+ # Gradio arayüzünü oluşturun
24
+ gr.Interface(fn=generate_image,
25
+ inputs=[gr.Image(type="pil", label="Initial Image"), gr.Textbox(label="Prompt")],
26
+ outputs=gr.Image(type="pil"),
27
+ title="Image-to-Image with Stable Diffusion",
28
+ description="Generate an image based on an initial image and a prompt.").launch()