đ¨ VibeCode Image Generator
Create stunning AI-generated images from text descriptions
import gradio as gr from gradio_client import Client import os from PIL import Image import io import base64 import requests def generate_image(prompt, negative_prompt="", guidance_scale=9): """ Generate an image using the Stable Diffusion API """ if not prompt.strip(): return None try: # Initialize the client client = Client("stabilityai/stable-diffusion") # Make the prediction result = client.predict( prompt=prompt, negative=negative_prompt, scale=guidance_scale, api_name="/infer" ) print(f"Debug - Result type: {type(result)}") print(f"Debug - Result: {result}") # Handle the specific format: list of dictionaries with 'image' keys if isinstance(result, list): for i, item in enumerate(result): try: if isinstance(item, dict) and 'image' in item: # Extract the image path from the dictionary image_path = item['image'] if os.path.exists(image_path): return Image.open(image_path) elif isinstance(item, str): # If it's a file path, load it as PIL Image if os.path.exists(item): return Image.open(item) # If it's a URL, download and return as PIL Image elif item.startswith(('http://', 'https://')): response = requests.get(item) return Image.open(io.BytesIO(response.content)) elif hasattr(item, 'save'): # PIL Image object return item except Exception as e: print(f"Debug - Error processing item {i}: {e}") continue # If no image found, try first item as fallback if len(result) > 0: first_item = result[0] if isinstance(first_item, dict) and 'image' in first_item: image_path = first_item['image'] if os.path.exists(image_path): return Image.open(image_path) elif isinstance(first_item, str) and os.path.exists(first_item): return Image.open(first_item) elif isinstance(result, dict) and 'image' in result: # Single dictionary result image_path = result['image'] if os.path.exists(image_path): return Image.open(image_path) elif isinstance(result, str): # Single string result - could be file path or URL if os.path.exists(result): return Image.open(result) elif result.startswith(('http://', 'https://')): response = requests.get(result) return Image.open(io.BytesIO(response.content)) elif hasattr(result, 'save'): # PIL Image object return result # If nothing worked, return None print("Debug - No valid image found in result") return None except Exception as e: print(f"Debug - Full error: {e}") return None def create_interface(): """ Create and configure the Gradio interface """ with gr.Blocks( title="đ¨ VibeCode Image Generator", theme=gr.themes.Soft(), css=""" .main-header { text-align: center; margin-bottom: 2rem; } footer { visibility: hidden; } .generate-btn { background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); border: none; border-radius: 8px; color: white; font-weight: bold; padding: 12px 24px; transition: transform 0.2s ease; } .generate-btn:hover { transform: translateY(-2px); } """ ) as demo: # Header gr.Markdown( """
Create stunning AI-generated images from text descriptions
Powered by Vibe Code Org. | Built with â¤ī¸