Spaces:
Sleeping

fugam commited on
Commit
929df1c
·
verified ·
1 Parent(s): 3d99728

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ # Charger le modèle Stable Diffusion
6
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
7
+ pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") # Utiliser GPU si disponible
8
+
9
+ # Fonction pour générer une image
10
+ def generate_image(prompt):
11
+ image = pipe(prompt).images[0]
12
+ return image
13
+
14
+ # Interface Gradio
15
+ interface = gr.Interface(
16
+ fn=generate_image,
17
+ inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Image Prompt"),
18
+ outputs=gr.Image(type="pil", label="Generated Image"),
19
+ title="Image Generator with Stable Diffusion",
20
+ description="Enter a description, and the AI will generate an image based on it!"
21
+ )
22
+
23
+ # Lancer l'application
24
+ if __name__ == "__main__":
25
+ interface.launch()