File size: 1,158 Bytes
e0e80e0
0cfcb98
e0e80e0
 
0cfcb98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e0e80e0
 
0cfcb98
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
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch

# Load Stable Diffusion model
model_id = "CompVis/stable-diffusion-v1-4"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")

# Function to generate an image
def generate_image(prompt, style):
    styled_prompt = f"{style} {prompt}"
    image = pipe(styled_prompt).images[0]
    return image

# Define Gradio interface
styles = ["Realistic", "Cartoon", "Abstract", "Fantasy"]

with gr.Blocks() as demo:
    gr.Markdown("# Illustrations4Free: Generate AI Illustrations")
    
    with gr.Row():
        prompt_input = gr.Textbox(label="Enter Your Prompt", placeholder="Describe the image you'd like to generate.")
        style_dropdown = gr.Dropdown(choices=styles, label="Choose a Style", value="Realistic")
    
    generate_button = gr.Button("Generate Illustration")
    output_image = gr.Image(label="Generated Illustration")

    generate_button.click(
        fn=generate_image,
        inputs=[prompt_input, style_dropdown],
        outputs=output_image
    )

demo.launch()