Download app.py from PunitSharma4242/Zenma-AI-Image-Generator: direct link, hf CLI and curl.
- Browser
- Download file 703 Bytes
-
https://huggingface.co/spaces/PunitSharma4242/Zenma-AI-Image-Generator/resolve/main/app.py
- Command line
-
hf download hf://spaces/PunitSharma4242/Zenma-AI-Image-Generator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PunitSharma4242/Zenma-AI-Image-Generator/resolve/main/app.py
703 Bytes
| import torch | |
| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| model_id = "runwayml/stable-diffusion-v1-5" | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float16 if device == "cuda" else torch.float32 | |
| ) | |
| pipe = pipe.to(device) | |
| pipe.load_lora_weights("./") | |
| def generate(prompt): | |
| image = pipe(prompt).images[0] | |
| return image | |
| demo = gr.Interface( | |
| fn=generate, | |
| inputs=gr.Textbox(label="Enter your prompt"), | |
| outputs=gr.Image(type="pil"), | |
| title="Zenma AI Image Generator", | |
| description="Generate images using a fine-tuned Stable Diffusion LoRA model" | |
| ) | |
| demo.launch() |