Download app.py from abmSS/Abdullah: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/spaces/abmSS/Abdullah/resolve/main/app.py
- Command line
-
hf download hf://spaces/abmSS/Abdullah/app.py
-
curl -L -o app.py https://huggingface.co/spaces/abmSS/Abdullah/resolve/main/app.py
1.82 kB
| from huggingface_hub import login | |
| import gradio as gr | |
| import numpy as np | |
| import random | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| huggingface-cli login | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| model_repo_id = "black-forest-labs/FLUX.1-dev" | |
| lora_repo_id = "abmSS/Amer" # Replace with your LoRA model | |
| if torch.cuda.is_available(): | |
| torch_dtype = torch.float16 | |
| else: | |
| torch_dtype = torch.float32 | |
| pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype) | |
| pipe.to(device) | |
| pipe.load_lora_weights(lora_repo_id) # Load LoRA weights | |
| MAX_SEED = np.iinfo(np.int32).max | |
| MAX_IMAGE_SIZE = 1024 | |
| def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps): | |
| if randomize_seed: | |
| seed = random.randint(0, MAX_SEED) | |
| generator = torch.Generator().manual_seed(seed) | |
| pipe.fuse_lora() # Enable LoRA | |
| image = pipe( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=guidance_scale, | |
| num_inference_steps=num_inference_steps, | |
| width=width, | |
| height=height, | |
| generator=generator, | |
| ).images[0] | |
| return image, seed | |
| with gr.Blocks() as demo: | |
| with gr.Column(): | |
| gr.Markdown(" # Text-to-Image with LoRA Support") | |
| prompt = gr.Text(label="Prompt", placeholder="Enter your prompt") | |
| run_button = gr.Button("Run") | |
| result = gr.Image(label="Result") | |
| gr.Examples( | |
| examples=["Astronaut in a jungle", "A futuristic city"], | |
| inputs=[prompt], | |
| ) | |
| gr.on( | |
| triggers=[run_button.click, prompt.submit], | |
| fn=infer, | |
| inputs=[prompt, "", 0, True, 1024, 1024, 7.5, 25], | |
| outputs=[result, None], | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |