File size: 936 Bytes
86def46
 
43555c1
 
86def46
43555c1
 
86def46
80645ad
86def46
80645ad
 
 
af1df58
43555c1
af1df58
43555c1
80645ad
43555c1
80645ad
43555c1
 
86def46
80645ad
 
 
43555c1
 
80645ad
 
43555c1
 
 
 
 
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
30
31
32
33
34
35
import gradio as gr
from PIL import Image
from diffusers import StableDiffusionImg2ImgPipeline
import torch

model_id = "runwayml/stable-diffusion-v1-5" 
device = "cuda" if torch.cuda.is_available() else "cpu"

pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(device)

def convert_simple(input_image: Image.Image) -> Image.Image:
    prompt = "A high contrast, dramatic photo, black and white, monochrome, grayscale"
    strength = 0.95
    
    input_image = input_image.convert("RGB").resize((512, 512))
    
    output_image = pipe(
        prompt=prompt,
        image=input_image,
        strength=strength, 
        guidance_scale=7.5
    ).images[0]
    
    final_bn_image = output_image.convert('L') 
    
    return final_bn_image

iface = gr.Interface(
    fn=convert_simple,
    inputs=[gr.Image(type="pil")],
    outputs="image",
)

if __name__ == "__main__":
    iface.launch()