Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,54 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
model = gr.load("models/Purz/face-projection")
|
5 |
|
6 |
-
def generate_image(text, seed):
|
7 |
-
if seed is not None:
|
8 |
-
random.seed(seed)
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
return model(text)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
examples = [
|
16 |
["Humanoid Cat Warrior, Full View", None],
|
17 |
["Warhammer Sisterhood", None],
|
@@ -20,7 +57,7 @@ examples = [
|
|
20 |
]
|
21 |
|
22 |
interface = gr.Interface(
|
23 |
-
fn=
|
24 |
inputs=[
|
25 |
gr.Textbox(label="Type here your imagination:", placeholder="Type or click an example..."),
|
26 |
gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
|
4 |
+
import requests
|
5 |
+
from PIL import Image
|
6 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
7 |
+
# from dotenv import load_dotenv
|
8 |
+
|
9 |
+
|
10 |
+
# Load the translation model
|
11 |
+
translation_model = AutoModelForSeq2SeqLM.from_pretrained("KarmaCST/nllb-200-distilled-600M-dz-to-en")
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained("KarmaCST/nllb-200-distilled-600M-dz-to-en")
|
13 |
+
|
14 |
+
|
15 |
model = gr.load("models/Purz/face-projection")
|
16 |
|
|
|
|
|
|
|
17 |
|
18 |
+
src_lang="dzo_Tibt"
|
19 |
+
tgt_lang="eng_Latn"
|
20 |
+
|
21 |
+
def translate_dzongkha_to_english(text):
|
22 |
+
translation_pipeline = pipeline("translation",
|
23 |
+
model=translation_model,
|
24 |
+
tokenizer=tokenizer,
|
25 |
+
src_lang=src_lang,
|
26 |
+
tgt_lang=tgt_lang)
|
27 |
+
|
28 |
+
translated_text = translation_pipeline(text)[0]['translation_text']
|
29 |
|
30 |
+
def generate_image(translated_text, seed):
|
31 |
+
if seed is not None:
|
32 |
+
random.seed(seed)
|
33 |
+
|
34 |
+
if text in [example[0] for example in examples]:
|
35 |
+
print(f"Using example: {text}")
|
36 |
+
|
37 |
+
# return model(text)
|
38 |
+
|
39 |
return model(text)
|
40 |
|
41 |
+
# model = gr.load("models/Purz/face-projection")
|
42 |
+
|
43 |
+
# def generate_image(text, seed):
|
44 |
+
# if seed is not None:
|
45 |
+
# random.seed(seed)
|
46 |
+
|
47 |
+
# if text in [example[0] for example in examples]:
|
48 |
+
# print(f"Using example: {text}")
|
49 |
+
|
50 |
+
# return model(text)
|
51 |
+
|
52 |
examples = [
|
53 |
["Humanoid Cat Warrior, Full View", None],
|
54 |
["Warhammer Sisterhood", None],
|
|
|
57 |
]
|
58 |
|
59 |
interface = gr.Interface(
|
60 |
+
fn=translate_dzongkha_to_english,
|
61 |
inputs=[
|
62 |
gr.Textbox(label="Type here your imagination:", placeholder="Type or click an example..."),
|
63 |
gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
|