Spaces:
Runtime error
Runtime error
cuneytkaya
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
3 |
+
import torch
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Stable Diffusion img2img modelini yükleme
|
7 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
8 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
9 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
+
|
11 |
+
def stylize_image(input_image, prompt):
|
12 |
+
input_image = input_image.convert("RGB")
|
13 |
+
input_image = input_image.resize((512, 512))
|
14 |
+
output = pipe(prompt=prompt, image=input_image, strength=0.75).images[0]
|
15 |
+
return output
|
16 |
+
|
17 |
+
# Gradio arayüzünü oluşturma
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=stylize_image,
|
20 |
+
inputs=[gr.Image(type="pil"), gr.Textbox(placeholder="Sanat tarzını girin...")],
|
21 |
+
outputs="image",
|
22 |
+
title="Sanat ve Stil Transferi Demo",
|
23 |
+
description="Bu demo, bir görüntüyü belirttiğiniz sanat tarzına dönüştürmek için Stable Diffusion modelini kullanır."
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch()
|