""" FHDR Uncensored Text-to-Image Generator Using kpsss34/FHDR_Uncensored via Diffusers (FluxPipeline) """ import logging from typing import Optional import gradio as gr from PIL import Image import torch from diffusers import FluxPipeline # ── Logging ──────────────────────────────────────────────────────────────────── logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", ) logger = logging.getLogger(__name__) # ── Model Loader ─────────────────────────────────────────────────────────────── pipe = None def load_model(): global pipe if pipe is None: logger.info("Loading FHDR model...") pipe = FluxPipeline.from_pretrained( "kpsss34/FHDR_Uncensored", torch_dtype=torch.bfloat16 ) pipe.enable_model_cpu_offload() logger.info("Model loaded successfully!") # ── Styles ───────────────────────────────────────────────────────────────────── STYLES: dict[str, str] = { "None": "", "Realistic": "photorealistic, ultra-detailed, 8K, sharp focus", "Anime": "anime style, vibrant colors, detailed linework", "Cyberpunk": "cyberpunk, neon lights, futuristic city", "Fantasy": "epic fantasy, cinematic lighting, concept art", } EXAMPLE_PROMPTS = [ ["A dragon flying over mountains", "Fantasy", 4.0, 768, 768], ["Cyberpunk city at night", "Cyberpunk", 4.0, 768, 768], ] # ── Helper ───────────────────────────────────────────────────────────────────── def apply_style_to_prompt(user_prompt: str, style_name: str) -> str: style_keywords = STYLES.get(style_name, "") return f"{user_prompt}, {style_keywords}" if style_keywords else user_prompt # ── Core Generation ──────────────────────────────────────────────────────────── def generate_image( user_prompt: str, style_name: str, guidance_scale: float, width: int, height: int, progress: gr.Progress = gr.Progress(), ) -> tuple[Optional[Image.Image], str]: if not user_prompt.strip(): return None, "⚠️ Please enter a prompt." try: progress(0.2, desc="Loading model...") load_model() final_prompt = apply_style_to_prompt(user_prompt, style_name) progress(0.5, desc="Generating image...") image = pipe( final_prompt, height=height, width=width, guidance_scale=guidance_scale, num_inference_steps=30, max_sequence_length=512, generator=torch.Generator("cpu").manual_seed(0) ).images[0] progress(1.0, desc="Done!") return image, "✅ Image generated successfully!" except Exception as e: logger.error("Error: %s", e, exc_info=True) return None, f"❌ Error: {str(e)}" # ── UI ───────────────────────────────────────────────────────────────────────── def build_interface() -> gr.Blocks: with gr.Blocks(title="FHDR Image Generator") as demo: gr.HTML("""
Powered by kpsss34/FHDR_Uncensored (Flux)