Spaces:
No application file
No application file
| 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() |