File size: 1,045 Bytes
feb159d
53e042c
feb159d
 
539cc3a
53e042c
 
 
 
 
539cc3a
53e042c
feb159d
cb1e61d
53e042c
 
 
cb1e61d
feb159d
 
 
53e042c
feb159d
 
 
cb1e61d
53e042c
feb159d
53e042c
feb159d
 
 
53e042c
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
import gradio as gr
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import torch

device = "cuda" if torch.cuda.is_available() else "cpu"

# Charger le modèle avec scheduler
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to(device)
pipe.enable_attention_slicing()

def generate_image(prompt):
    if prompt.strip() == "":
        return None
    image = pipe(prompt, num_inference_steps=20, height=512, width=512).images[0]
    return image

description = """
# 🌄 Générateur de Paysages IA
Tape un mot-clé ou une idée de paysage et clique sur **Générer** !
"""

demo = gr.Interface(
    fn=generate_image,
    inputs=gr.Textbox(label="Description du paysage", placeholder="ex : forêt mystique au coucher du soleil"),
    outputs=gr.Image(label="Image générée"),
    title="Paysage IA",
    description=description,
)

demo.launch()