from utils.image import generate_image_data, save_image_from_b64 import gradio as gr detailed_prompts = { "Smart Farming Dashboard": "A panoramic view of a verdant rice paddy at dawn, with a rugged farmer in traditional attire holding a sleek smartphone in his right hand. On the phone’s screen is a semi-transparent holographic dashboard showing real-time soil moisture graphs and sensor icons. In the foreground, three cylindrical soil probes protrude from the earth, each glowing faintly green. Soft golden sunlight filters through low mist, casting long shadows. Render in ultra-realistic style, warm color palette, depth of field focusing on the phone and probes.", "Voice-Based Study Companion": "Interior of a cozy study nook at twilight, with a teenage student wearing headphones and speaking into a tabletop AI “pod” device. From the device, pastel-blue sound waves ripple outward. Floating above are translucent speech bubbles containing quiz questions and answer choices. Behind, a wall-mounted bookshelf is softly lit by a smart lamp displaying a progress bar. Use a semi-cartoon style with gentle gradients, slight film grain, side lighting from lamp.", "Elderly Health Alert System": "A warmly lit living room. An elderly woman in a floral dress sits comfortably in an armchair, a biometric wristband on her left wrist glowing soft red. Her adult daughter stands beside her, holding a smartphone that displays a large red alert icon and her mother’s heart-rate graph. In the background, family photos line the wall. Style: photorealistic with high dynamic range, slight vignette around edges, camera angle at eye level, muted pastel tones.", "Interactive Traffic Control Network": "A bird’s-eye view of a modern city intersection at dusk, roads illuminated with smart LED lane markings. Autonomous cars navigate smoothly, each outlined in thin neon lines. On one corner, a control tower with a large curved screen shows live traffic heatmaps in red and blue. A grid of sensors and cameras hover above the roads. Style: cyber-punk aesthetic, high contrast, neon color accents, minimal human presence.", "Pitch-Ready Animated Resume": "A clean white canvas background with a horizontal timeline running across the center. Along the timeline are five circular nodes, each containing a semi-realistic icon: laptop with code, team of people, bar chart growth, AI brain, and mortarboard cap. Below each node, a short phrase (e.g., ‘Built Web App,’ ‘Led 5-Person Team’). Surrounding the timeline are subtle floating data points and arrows. Render in flat-vector style, bright primary colors, no outlines, isometric perspective.", "Dream2Scene Storyboard Panel": "Single widescreen panel depicting a young writer at a wooden desk in a small attic room. Outside the triangular window, a starry night sky and a full moon. From the writer’s typewriter, faint ethereal illustrations of flying dragons and castles drift upward and fade into the air. The room is lit by a single vintage desk lamp casting warm yellow light. Style: painterly watercolor with soft brush strokes, slight paper texture.", "Global Video-Content Advisor": "A modern coworking space with a content creator seated at a desk reviewing a large monitor. On the screen, three video thumbnail prototypes: one with a bold title overlay, one with a smiling host framed center, and one with dynamic background graphics. Floating above the monitor are three speech-bubble style tips: ‘Increase CTR,’ ‘Use face close-up,’ ‘Add branding logo.’ Use a clean digital-illustration style, cool blue-and-white color palette, subtle shadows, top-down spotlight lighting." } def generate(prompt, width, height, steps, seed, negative_prompt): try: result = generate_image_data( prompt=prompt, width=width, height=height, steps=steps, seed=seed, negative_prompt=negative_prompt ) if "data" not in result or not result["data"]: return "❌ Failed to generate image." b64_image = result["data"][0]["b64_json"] return save_image_from_b64(b64_image) except Exception as e: return f"❌ Error: {str(e)}" with gr.Blocks(theme=gr.themes.Base(), css="body {background-color: #f9fafb;}") as demo: gr.Markdown( """ # 🧠 Project Visualizer Agent *Turn your ideas into visuals — instantly!* Describe your project in detail, or select a sample idea below to get started. We'll generate a high-quality image that represents it using advanced AI image generation models. Perfect for pitches, presentations, and storytelling. """ ) with gr.Row(): with gr.Column(scale=2): prompt_input = gr.Textbox( label="✨ Prompt", placeholder="A futuristic cyberpunk city at night with flying cars", lines=10 ) negative_input = gr.Textbox( label="🚫 Negative Prompt", placeholder="blurry, distorted, low resolution", lines=2 ) with gr.Column(scale=1): width_input = gr.Slider(256, 2048, step=64, value=1024, label="Width (px)") height_input = gr.Slider(256, 2048, step=64, value=1024, label="Height (px)") steps_input = gr.Slider(1, 100, step=1, value=4, label="Inference Steps") seed_input = gr.Number(value=-1, label="Seed (-1 for random)") example_selector = gr.Dropdown( choices=list(detailed_prompts.keys()), label="💡 Choose an Example Prompt", value=None ) def fill_prompt(example_key): return detailed_prompts.get(example_key, "") example_selector.change(fn=fill_prompt, inputs=example_selector, outputs=prompt_input) with gr.Row(): generate_btn = gr.Button("🚀 Generate Image", variant="primary") output_image = gr.Image(type="filepath", label="🖼️ Generated Image", height=512) generate_btn.click( fn=generate, inputs=[prompt_input, width_input, height_input, steps_input, seed_input, negative_input], outputs=output_image ) # if __name__ == "__main__": demo.launch(mcp_server=True, share=False)