Spaces:
Runtime error
Runtime error
Download app.py from antonio8876/coloringtest: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/antonio8876/coloringtest/resolve/main/app.py
- Command line
-
hf download hf://spaces/antonio8876/coloringtest/app.py
-
curl -L -o app.py https://huggingface.co/spaces/antonio8876/coloringtest/resolve/main/app.py
1.55 kB
| import gradio as gr | |
| from diffusers import FluxPipeline | |
| import torch | |
| import os | |
| from huggingface_hub import login | |
| import logging | |
| # ΠΠ°ΡΡΡΠΎΠΉΠΊΠ° Π»ΠΎΠ³ΠΈΡΠΎΠ²Π°Π½ΠΈΡ | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| # ΠΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΡ | |
| logger.info("Starting authentication") | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| login(HF_TOKEN) | |
| logger.info("Authentication successful") | |
| # ΠΠ°Π³ΡΡΠ·ΠΊΠ° ΠΌΠΎΠ΄Π΅Π»ΠΈ | |
| logger.info("Loading base model") | |
| base_model = "black-forest-labs/FLUX.1-dev" | |
| pipe = FluxPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16) | |
| logger.info("Base model loaded") | |
| logger.info("Loading LoRA weights") | |
| pipe.load_lora_weights("prithivMLmods/Coloring-Book-Flux-LoRA") | |
| logger.info("LoRA weights loaded") | |
| pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
| logger.info("Model moved to device") | |
| def generate_image(prompt, num_steps=50, guidance_scale=7.5): | |
| logger.info(f"Generating image with prompt: {prompt}") | |
| image = pipe(prompt, num_inference_steps=num_steps, guidance_scale=guidance_scale).images[0] | |
| logger.info("Image generated") | |
| return image | |
| iface = gr.Interface( | |
| fn=generate_image, | |
| inputs=[ | |
| gr.Textbox(label="Prompt", value="Coloring Book, A black and white drawing of a fox"), | |
| gr.Slider(label="Number of Steps", minimum=1, maximum=100, value=50), | |
| gr.Slider(label="Guidance Scale", minimum=1, maximum=20, value=7.5) | |
| ], | |
| outputs=gr.Image(label="Generated Image") | |
| ) | |
| logger.info("Launching Gradio interface") | |
| iface.launch() |