File size: 1,121 Bytes
9171e4e
daf62cf
 
 
9171e4e
daf62cf
 
 
9171e4e
daf62cf
9171e4e
daf62cf
 
 
 
 
 
 
 
 
 
4938098
daf62cf
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
from diffusers import StableDiffusionImg2ImgPipeline
import torch
from PIL import Image

# Modelinizi yükleyin
model_id = "radames/stable-diffusion-2-1-img2img"
device = "cuda" if torch.cuda.is_available() else "cpu"

pipeline = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, use_auth_token=True).to(device)

def generate_image(img, prompt):
    # Görüntüyü PIL Image olarak açın ve boyutunu değiştirin (isteğe bağlı)
    image = img.resize((512, 512))
    
    # Modeli çağırarak görüntüyü üretin
    with torch.no_grad():
        output_image = pipeline(prompt=prompt, init_image=image, strength=0.75, guidance_scale=7.5)["sample"][0]
    
    # Çıktıyı PIL Image olarak döndürün
    return output_image

# Gradio arayüzünü oluşturun
gr.Interface(fn=generate_image,
             inputs=[gr.Image(type="pil", label="Initial Image"), gr.Textbox(label="Prompt")],
             outputs=gr.Image(type="pil"),
             title="Image-to-Image with Stable Diffusion",
             description="Generate an image based on an initial image and a prompt.").launch()