app.py
CHANGED
@@ -1,21 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
|
|
5 |
|
6 |
-
|
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
)
|
|
|
|
|
|
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
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()
|