AI Image Generator
Generate amazing images with the power of AI!
import gradio as gr from huggingface_hub import InferenceClient import random import time # Set up the client for the Hugging Face model client = InferenceClient(model="GenAIJake/g3na1j8k3") def generate_image(prompt, negative_prompt="", num_inference_steps=30, guidance_scale=7.5): try: # Add a small delay to show the loading indicator time.sleep(0.5) # Call the model API image = client.text_to_image( prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, ) return image, None except Exception as e: return None, f"Error generating image: {str(e)}" # Example prompts to help users get started example_prompts = [ ["A serene lake surrounded by mountains at sunset"], ["A futuristic cityscape with flying cars"], ["A photo-realistic cat wearing sunglasses and a hat"], ["A fantasy castle with dragons flying around it"], ["An astronaut riding a horse on the moon, digital art"] ] # Custom CSS for styling custom_css = """ .gradio-container { font-family: 'Arial', sans-serif; } .main-header { text-align: center; margin-bottom: 2rem; } .example-prompt { cursor: pointer; padding: 0.5rem; border-radius: 0.5rem; background-color: #f7f7f7; margin-bottom: 0.5rem; transition: background-color 0.3s; } .example-prompt:hover { background-color: #e0e0e0; } """ # Create the Gradio interface with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: gr.HTML("""
Generate amazing images with the power of AI!
Click on any example to use it as your prompt:
") examples = gr.Examples( example_prompts, inputs=[prompt], examples_per_page=5 ) with gr.Column(scale=3): # Output area with error display output_image = gr.Image(label="Generated Image", type="pil") error_output = gr.Textbox(label="Error (if any)", visible=False) # Instructions section with gr.Accordion("How to use", open=False): gr.HTML("""