import gradio as gr import os from huggingface_hub import InferenceClient # 🔑 token HF_TOKEN = os.getenv("image") client = InferenceClient( model="stabilityai/stable-diffusion-xl-base-1.0", token=HF_TOKEN ) def generate_image(prompt, width, height): if not prompt.strip(): return None, "⚠️ Enter prompt" try: image = client.text_to_image( prompt, width=int(width), height=int(height) ) return image, "✅ Image generated" except Exception as e: return None, f"❌ Error: {str(e)}" # 🎨 CLEAN MODERN UI with gr.Blocks( theme=gr.themes.Soft( primary_hue="blue", secondary_hue="sky", neutral_hue="gray" ) ) as app: # ✅ MAIN TITLE (fixed visibility) gr.Markdown( """ # 🎨 AI Text → Image Generator ### ✨ Generate high-quality AI images using Stable Diffusion """, elem_id="title" ) with gr.Row(): prompt = gr.Textbox( label="✍️ Enter Prompt", placeholder="A futuristic city at night, cinematic lighting...", lines=3 ) with gr.Row(): width = gr.Slider(256, 1024, value=768, step=64, label="📏 Width") height = gr.Slider(256, 1024, value=768, step=64, label="📐 Height") with gr.Row(): btn = gr.Button("🚀 Generate Image", variant="primary") output_img = gr.Image(label="🖼️ Result", type="pil") status = gr.Textbox(label="📢 Status") btn.click(generate_image, [prompt, width, height], [output_img, status]) app.launch()