VaneM commited on
Commit
b058173
1 Parent(s): 0ba78e4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
2
+ from transformers import pipeline
3
+ import torch
4
+ from IPython.display import clear_output
5
+ import gradio as gr
6
+
7
+ model_name = "stabilityai/stable-diffusion-2"
8
+ scheduler = EulerDiscreteScheduler.from_pretrained(model_name, subfolder="scheduler")
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_name, scheduler=scheduler, revision="fp16", torch_dtype=torch.float16)
10
+
11
+ # Movemos el pipeline a GPU para tener una inferencia más rápida.
12
+ device = "cuda" if torch.cuda.is_available() else "cpu"
13
+ pipe = pipe.to(device)
14
+ pipe.enable_attention_slicing()
15
+
16
+ # Cargamos el modelo traductor y creamos el pipeline para traducir al ingles
17
+ spanish_model_name = "Helsinki-NLP/opus-mt-es-en"
18
+ translator_es_en = pipeline("translation", model=spanish_model_name)
19
+
20
+ def predict(text):
21
+ prompt_es = text
22
+ english_text = translator_es_en(prompt_es)
23
+ prompt_en = english_text[0]['translation_text']
24
+ image = pipe(prompt_en).images[0]
25
+ return image
26
+
27
+ description = """
28
+ <h2 style="text-align:center">Programa para generar imágenes a partir de texto con Stable Diffusion 2</h2>
29
+ <h2 style="text-align:center">Prompt en español!!</h2>
30
+ """
31
+
32
+ gr.Interface(fn=predict,
33
+ title="Texto a Imagen en Español",
34
+ inputs= gr.Textbox("", max_lines = 2, label = "Inserte su texto aqui"),
35
+ outputs = "image",
36
+ description = description).launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ transformers
2
+ gradio
3
+ torch
4
+ sacremoses==0.0.53
5
+ sentencepiece==0.1.97
6
+ accelerate
7
+ scipy
8
+ diffusers @ git+https://github.com/huggingface/diffusers.git