Spaces:
Runtime error
Runtime error
File size: 1,549 Bytes
30643a8 f43013d 30643a8 cc59bff 9157c8e cc59bff 9157c8e cc59bff 9157c8e 30643a8 f43013d 9157c8e f43013d 9157c8e f43013d 9157c8e f43013d 9157c8e f43013d 9157c8e f43013d 9157c8e f43013d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 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() |