Spaces:
Runtime error
Runtime error
Commit
·
650ec6e
1
Parent(s):
8cff0ad
Upload
Browse files- README.md +5 -5
- app.py +68 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
app_file: app.py
|
| 8 |
-
pinned:
|
| 9 |
---
|
| 10 |
|
| 11 |
# Configuration
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Kinda-English ruDALL-E
|
| 3 |
+
emoji: 🧑🎨
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
app_file: app.py
|
| 8 |
+
pinned: true
|
| 9 |
---
|
| 10 |
|
| 11 |
# Configuration
|
app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from gradio.mix import Series
|
| 5 |
+
from rudalle.pipelines import generate_images
|
| 6 |
+
from rudalle import get_rudalle_model, get_tokenizer, get_vae
|
| 7 |
+
|
| 8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
dalle = get_rudalle_model("Malevich", pretrained=True, fp16=True, device=device)
|
| 10 |
+
tokenizer = get_tokenizer()
|
| 11 |
+
vae = get_vae().to(device)
|
| 12 |
+
|
| 13 |
+
def dalle_wrapper(prompt: str):
|
| 14 |
+
top_k, top_p = random.choice([
|
| 15 |
+
(1024, 0.98),
|
| 16 |
+
(512, 0.97),
|
| 17 |
+
(384, 0.96),
|
| 18 |
+
])
|
| 19 |
+
|
| 20 |
+
images , _ = generate_images(
|
| 21 |
+
prompt,
|
| 22 |
+
tokenizer,
|
| 23 |
+
dalle,
|
| 24 |
+
vae,
|
| 25 |
+
top_k=top_k,
|
| 26 |
+
images_num=1,
|
| 27 |
+
top_p=top_p
|
| 28 |
+
)
|
| 29 |
+
title = f"<b>{prompt}</b>"
|
| 30 |
+
return title, images[0]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
translator = gr.Interface.load("huggingface/facebook/wmt19-en-ru",
|
| 34 |
+
inputs=[gr.inputs.Textbox(label="What would you like to see?")])
|
| 35 |
+
outputs = [
|
| 36 |
+
gr.outputs.HTML(label=""),
|
| 37 |
+
gr.outputs.Image(label=""),
|
| 38 |
+
]
|
| 39 |
+
generator = gr.Interface(fn=dalle_wrapper, inputs="text", outputs=outputs)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
description = (
|
| 43 |
+
"ruDALL-E is a 1.3B params text-to-image model by SberAI (links at the bottom). "
|
| 44 |
+
"This demo uses an English-Russian translation model to adapt the prompts. "
|
| 45 |
+
"Try pressing [Submit] multiple times to generate new images!"
|
| 46 |
+
)
|
| 47 |
+
article = (
|
| 48 |
+
"<p style='text-align: center'>"
|
| 49 |
+
"<a href='https://github.com/sberbank-ai/ru-dalle'>GitHub</a> | "
|
| 50 |
+
"<a href='https://habr.com/ru/company/sberbank/blog/586926/'>Article (in Russian)</a>"
|
| 51 |
+
"</p>"
|
| 52 |
+
)
|
| 53 |
+
examples = [["A white cat sitting in a cardboard box"],
|
| 54 |
+
["Город в стиле киберпанк"],
|
| 55 |
+
["A colorful photo of coral reef"]]
|
| 56 |
+
|
| 57 |
+
series = Series(translator, generator,
|
| 58 |
+
title='Kinda-English ruDALL-E',
|
| 59 |
+
description=description,
|
| 60 |
+
article=article,
|
| 61 |
+
layout='horizontal',
|
| 62 |
+
theme='huggingface',
|
| 63 |
+
examples=examples,
|
| 64 |
+
allow_flagging=False,
|
| 65 |
+
live=False,
|
| 66 |
+
)
|
| 67 |
+
series.launch()
|
| 68 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
rudalle==0.0.1rc1
|