File size: 1,403 Bytes
1f76202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import torch
from diffusers import DiffusionPipeline
import gradio as gr

# Load the CogVideoX diffusion model
pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-5b", torch_dtype=torch.float16)
pipe.load_lora_weights("a-r-r-o-w/cogvideox-disney-adamw-3000-0.0003")
pipe.to("cuda")  # Send the model to GPU if available

# Function to generate an image based on user prompt
def generate_image(prompt):
    # Generate an image using the CogVideoX model
    with torch.inference_mode():
        image = pipe(prompt).images[0]
    return image

# Set up the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Image Generation using CogVideoX (THUDM/CogVideoX-5b) with LoRA")

    # Input for user to provide a text prompt
    prompt_input = gr.Textbox(label="Enter Text Prompt", 
                               placeholder="e.g. 'Astronaut in a jungle, cold color palette, muted colors, detailed, 8k'", 
                               value="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
    
    # Output to display the generated image
    output_image = gr.Image(label="Generated Image")

    # Button to trigger image generation
    generate_button = gr.Button("Generate Image")

    # Link button click to image generation function
    generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image)

# Launch the Gradio app
demo.launch()