| import streamlit as st |
| import torch |
| from diffusers import StableDiffusionPipeline |
| import matplotlib.pyplot as plt |
|
|
| |
| st.title("Générateur d'Images avec Stable Diffusion") |
|
|
| |
| device = "cuda" if torch.cuda.is_available() else "cpu" |
|
|
| |
| model_id = "CompVis/stable-diffusion-v1-4" |
| pipe = StableDiffusionPipeline.from_pretrained(model_id).to(device) |
|
|
| |
| def generate_image(prompt): |
| with torch.no_grad(): |
| image = pipe(prompt).images[0] |
| return image |
|
|
| |
| prompt = st.text_input("Entrez un prompt pour générer une image :", "a fantasy landscape with mountains and a river") |
|
|
| |
| if st.button("Générer l'Image"): |
| if prompt: |
| with st.spinner("Génération de l'image..."): |
| generated_image = generate_image(prompt) |
|
|
| |
| st.image(generated_image, caption=prompt, use_column_width=True) |
| else: |
| st.error("Veuillez entrer un prompt.") |
|
|