Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +11 -23
- requirements.txt +1 -4
app.py
CHANGED
@@ -1,35 +1,23 @@
|
|
1 |
-
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
2 |
-
from transformers import pipeline
|
3 |
-
import torch
|
4 |
import gradio as gr
|
5 |
-
|
6 |
-
model_name = "stabilityai/stable-diffusion-2"
|
7 |
-
scheduler = EulerDiscreteScheduler.from_pretrained(model_name, subfolder="scheduler")
|
8 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_name, scheduler=scheduler, revision="fp16", torch_dtype=torch.float16)
|
9 |
-
|
10 |
-
# Movemos el pipeline a GPU para tener una inferencia más rápida.
|
11 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
-
pipe = pipe.to(device)
|
13 |
-
pipe.enable_attention_slicing()
|
14 |
|
15 |
# Cargamos el modelo traductor y creamos el pipeline para traducir al ingles
|
16 |
spanish_model_name = "Helsinki-NLP/opus-mt-es-en"
|
17 |
translator_es_en = pipeline("translation", model=spanish_model_name)
|
18 |
|
19 |
-
def
|
20 |
prompt_es = text
|
21 |
english_text = translator_es_en(prompt_es)
|
22 |
prompt_en = english_text[0]['translation_text']
|
23 |
-
|
24 |
-
return image
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
"""
|
30 |
-
|
31 |
-
gr.Interface(fn=predict,
|
32 |
-
title="Texto a Imagen en Español",
|
33 |
inputs= gr.Textbox("", max_lines = 2, label = "Inserte su texto aqui"),
|
34 |
-
outputs = "
|
35 |
-
description = description).launch(debug=True)
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Cargamos el modelo traductor y creamos el pipeline para traducir al ingles
|
5 |
spanish_model_name = "Helsinki-NLP/opus-mt-es-en"
|
6 |
translator_es_en = pipeline("translation", model=spanish_model_name)
|
7 |
|
8 |
+
def translate(text):
|
9 |
prompt_es = text
|
10 |
english_text = translator_es_en(prompt_es)
|
11 |
prompt_en = english_text[0]['translation_text']
|
12 |
+
return prompt_en
|
|
|
13 |
|
14 |
+
title="Texto a Imagen en Español con Stable Diffusion 2.0"
|
15 |
+
article = """
|
16 |
+
El modelo usa:
|
17 |
+
- Texto a Imagen [Stable Diffusion 2.0](https://huggingface.co/stabilityai/stable-diffusion-2),
|
18 |
+
- Para las traducciones [Helsinki-NLP](https://huggingface.co/Helsinki-NLP)
|
19 |
+
\n ... y mucha magia ☺
|
20 |
"""
|
21 |
+
gr.Interface(fn=translate,
|
|
|
|
|
22 |
inputs= gr.Textbox("", max_lines = 2, label = "Inserte su texto aqui"),
|
23 |
+
outputs = "text").load("models/stabilityai/stable-diffusion-2", title = title, article=article).launch(debug=True)
|
|
requirements.txt
CHANGED
@@ -2,7 +2,4 @@ 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
|
|
|
2 |
gradio
|
3 |
torch
|
4 |
sacremoses==0.0.53
|
5 |
+
sentencepiece==0.1.97
|
|
|
|
|
|