Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
from diffusers import AutoPipelineForText2Image
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
img_generator1 = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16)
|
7 |
+
img_generator1.to("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
+
|
9 |
+
# Chargement du modèle Stable Diffusion v1.4 depuis Hugging Face
|
10 |
+
img_generator2 = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4",torch_dtype=torch.float16 if device == "cuda" else torch.float32)
|
11 |
+
img_generator2.to("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
+
|
13 |
+
|
14 |
+
# Fonction de génération d’image à partir du texte
|
15 |
+
def text_to_image(prompt, model_name):
|
16 |
+
if model_name == 'kandinsky-2-2-decoder':
|
17 |
+
return img_generator1(prompt=prompt).images[0]
|
18 |
+
else:
|
19 |
+
return img_generator2(prompt=prompt).images[0]
|
20 |
+
|
21 |
+
# Interface Gradio simple
|
22 |
+
gr.Interface(
|
23 |
+
fn=text_to_image,
|
24 |
+
inputs= [gr.Textbox(label="Entrez une description (prompt)"),
|
25 |
+
gr.Dropdown(choices =['kandinsky-2-2-decoder', 'stable-diffusion-v1-4'], label = 'Model Name')],
|
26 |
+
outputs=gr.Image(type="pil", label="Image générée"),
|
27 |
+
title="Générateur d'Images à partir de Texte",
|
28 |
+
description="Entrez un texte pour générer une image"
|
29 |
+
).launch()
|