Spaces:
Build error
Build error
Download app.py from rzAI6/Image-class: direct link, hf CLI and curl.
- Browser
- Download file 887 Bytes
-
https://huggingface.co/spaces/rzAI6/Image-class/resolve/main/app.py
- Command line
-
hf download hf://spaces/rzAI6/Image-class/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rzAI6/Image-class/resolve/main/app.py
887 Bytes
| import gradio as gr | |
| import requests | |
| import torch | |
| from PIL import Image | |
| from io import BytesIO | |
| from diffusers import StableDiffusionImg2ImgPipeline | |
| device = "cpu" | |
| model_id_or_path = "runwayml/stable-diffusion-v1-5" | |
| pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.get_default_dtype(),) | |
| pipe = pipe.to(device) | |
| pipe.enable_attention_slicing() | |
| def transform (init_image, textPrompt, strength=0.5, guidance_scale=15): | |
| init_image = Image.open(init_image).convert("RGB") | |
| init_image = init_image.resize((768, 512)) | |
| images = pipe(prompt=textPrompt, image=init_image, strength=strength, guidance_scale=guidance_scale).images | |
| image = images[0] | |
| return image | |
| demo = gr.Interface( | |
| fn=transform, | |
| inputs=[gr.Image(type='filepath'), "text", gr.Slider(0,1), gr.Slider(1,30)], | |
| outputs=["image"], | |
| allow_flagging="never" | |
| ) | |
| demo.launch() |