''' sudo apt-get update && sudo apt-get install git-lfs ffmpeg cbm # Clone this repository git clone https://huggingface.co/spaces/svjack/illustrious-xl-v1.0-demo # Go into the repository cd illustrious-xl-v1.0-demo ### Install dependencies ### conda create --name py310 python=3.10 conda activate py310 # Install ipykernel and add the environment to Jupyter pip install ipykernel python -m ipykernel install --user --name py310 --display-name "py310" pip install -r requirements.txt python app.py ''' # Import necessary libraries import gradio as gr import diffusers import torch # Automatically detect if CUDA is available and set the device accordingly device = "cuda" if torch.cuda.is_available() else "cpu" # Load the model from the specified file outside the function to ensure better performance model = diffusers.StableDiffusionXLPipeline.from_single_file( "https://huggingface.co/Liberata/illustrious-xl-v1.0/blob/main/Illustrious-XL-v1.0.safetensors", torch_dtype=torch.float16 ).to(device) # Move the model to the detected device # Define the function to generate an image from text using the pre-loaded model def generate_image(prompt, guidance_scale, num_inference_steps): # Generate the image from the text prompt with the specified parameters image = model(prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0] return image # Create a Gradio interface for the text-to-image generation with gr.Blocks() as demo: # Add some documentation using HTML gr.HTML("""

😊 Text-to-Image Generation with Liberata/illustrious-xl-v1.0

This app allows you to generate images from text prompts using the Liberata/illustrious-xl-v1.0 model.

Simply enter a text prompt, adjust the parameters, and click the 'Generate Image' button to see the generated image.

""") # Create a two-column layout with gr.Row(): with gr.Column(): # Create a textbox for the user to input the text prompt prompt_input = gr.Textbox(label="Text Prompt") # Create sliders for the guidance scale and number of inference steps guidance_scale_slider = gr.Slider(1, 20, value=7.5, step=0.1, label="Guidance Scale") num_inference_steps_slider = gr.Slider(1, 100, value=50, step=1, label="Number of Inference Steps") # Add a resolution input #resolution_input = gr.Textbox(value="1536x1536", label="Resolution") with gr.Column(): # Create an image output to display the generated image image_output = gr.Image(label="Generated Image") # Create a button to trigger the image generation generate_button = gr.Button("Generate Image") # Define the event listener for the button click generate_button.click(fn=generate_image, inputs=[prompt_input, guidance_scale_slider, num_inference_steps_slider], outputs=image_output) # Add examples examples = [ ["1girl,[artist:WANKE|artist:free_style |[artist:ningen_mame]|ciloranko],tokoyami towa,mesugaki,devil,sensitive,dark theme,glowing eyes,silhouette,sword"], ["1boy, solo, hair: long red hair, flowing in wind, partially obscuring face, eyes: hidden by hair, but implied intense gaze, clothing: flowing tattered cloak, crimson and black, simple dark shirt underneath, leather gloves, setting: wide shot of sprawling ruins, fires burning intensely, night, full moon obscured by smoke, wind blowing debris, **scattered playing cards on ground**, **Joker card prominently visible**, pose: standing amidst scattered cards, arms slightly outstretched, as if gesturing to the chaos, mysterious aura, atmosphere: chaotic, uncertain, fateful, ominous, powerful, dramatic, sense of impending doom, quality: masterpiece, extremely aesthetic, epic scale, highly detailed ruins, dynamic composition, rim lighting from fires and moon, vibrant fire colors, vivid colors, saturated, artist style: by frank frazetta, by moebius (for lineart and detail), trending on artstation"], ["1boy, solo, fiery messy hair, red hair, orange hair, red eyes, glowing eyes, intense gaze, torn dark clothes, tattered robes, worn leather, long sleeves, ruins, burning city, fire, embers, smoke, ash, night, desolate wasteland, collapsed buildings, looking back, determined look, serious expression, masterpiece, extremely aesthetic, dreamy atmosphere, intense warm colors, vivid colors, saturated, detailed background, dramatic lighting, by rella, by konya karasue, vivid colors, saturated"], ["1boy, Digital anime-style ALBEDO has light gray, messy hair, blue eyes. Shy look, in white & blue hoodie, at cozy café table with food. Shelf background"], ["1boy ,Digital anime-style CHONGYUN has shiny silver hair, green eyes. Cheerful expression, in bright blue T-shirt, at luxurious restaurant with Belgian chocolates. Elegant crystal chandelier background."], ] gr.Examples(examples, [prompt_input, guidance_scale_slider, num_inference_steps_slider]) # Launch the Gradio app with share=True if __name__ == "__main__": demo.launch(share=True, show_error=True)