File size: 860 Bytes
b744973
 
3423cd6
 
b744973
 
3423cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from diffusers import DiffusionPipeline
import gradio as gr

# Load the model
model_id = "CompVis/ldm-text2im-large-256"
ldm = DiffusionPipeline.from_pretrained(model_id)

# Function to generate image
def generate_image(prompt):
    try:
        images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6)
        return images.images[0]
    except Exception as e:
        return f"Error generating image: {str(e)}"

# Gradio interface setup
interface = gr.Interface(
    fn=generate_image,
    inputs="text",
    outputs="image",
    title="Mashdemy Demo Image Generator App",
    description="Type a prompt and click submit to generate an image.",
    examples=[
        "a clown reading a book", 
        "a cat using a laptop", 
        "An elephant on grass"
    ]
)

# Launch the interface with sharing enabled
interface.launch(share=True)