Spaces:
Runtime error
Runtime error
Download app.py from MuhammedIjas555444/Image: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/MuhammedIjas555444/Image/resolve/main/app.py
- Command line
-
hf download hf://spaces/MuhammedIjas555444/Image/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MuhammedIjas555444/Image/resolve/main/app.py
1.01 kB
| import torch | |
| print(f"Is CUDA available: {torch.cuda.is_available()}") | |
| # True | |
| print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}") | |
| # Tesla T4 | |
| import gradio as gr | |
| from diffusers import StableDiffusionImg2ImgPipeline | |
| from PIL import Image | |
| import torch | |
| pipe = StableDiffusionImg2ImgPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-v1-5" | |
| ) | |
| pipe = pipe.to("cpu") # safe for free plan | |
| def generate(input_image, prompt): | |
| if input_image is None: | |
| return None | |
| image = Image.fromarray(input_image).convert("RGB") | |
| image = image.resize((512, 512)) | |
| result = pipe( | |
| prompt=prompt, | |
| image=image, | |
| strength=0.5, | |
| num_inference_steps=10, | |
| guidance_scale=6 | |
| ).images[0] | |
| return result | |
| iface = gr.Interface( | |
| fn=generate, | |
| inputs=[ | |
| gr.Image(type="numpy", label="Upload Image"), | |
| gr.Textbox(label="Enter prompt") | |
| ], | |
| outputs=gr.Image(), | |
| title="⚡ Fast Image Regenerator" | |
| ) | |
| iface.launch() |