Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ from huggingface_hub import hf_hub_download
|
|
30 |
from safetensors.torch import load_file, save_file
|
31 |
from diffusers import FluxPipeline
|
32 |
from PIL import Image, ImageDraw, ImageFont
|
33 |
-
from transformers import pipeline,
|
34 |
from refiners.fluxion.utils import manual_seed
|
35 |
from refiners.foundationals.latent_diffusion import Solver, solvers
|
36 |
from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler import (
|
@@ -38,9 +38,11 @@ from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler i
|
|
38 |
UpscalerCheckpoints,
|
39 |
)
|
40 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
model = MT5ForConditionalGeneration.from_pretrained("google/mt5-xl")
|
43 |
-
tokenizer = T5Tokenizer.from_pretrained("google/mt5-xl")
|
44 |
|
45 |
def log(msg):
|
46 |
print(f'{datetime.now().time()} {msg}')
|
@@ -716,22 +718,14 @@ def translate(txt,to_lang="en",from_lang=False):
|
|
716 |
log(f'CALL translate')
|
717 |
if not from_lang:
|
718 |
from_lang = get_language(txt)
|
719 |
-
print(f"translating from {from_lang} to {to_lang}")
|
720 |
if(from_lang == to_lang):
|
721 |
log(f'RET translate with txt as {txt}')
|
722 |
return txt
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
log(f'DBG translate chunk is {chunk}')
|
729 |
-
inputs = tokenizer.encode(prefix+chunk, return_tensors="pt", truncation=False, add_special_tokens=True)
|
730 |
-
gen = model.generate(inputs,num_beams=3)
|
731 |
-
toks = tokenizer.decode(gen[0], skip_special_tokens=True)
|
732 |
-
ret = ret + ("" if ret == "" else " ") + toks
|
733 |
-
log(f'RET translate with ret as {ret}')
|
734 |
-
return ret
|
735 |
|
736 |
@spaces.GPU(duration=300)
|
737 |
def handle_generation(artist,song,genre,lyrics):
|
|
|
30 |
from safetensors.torch import load_file, save_file
|
31 |
from diffusers import FluxPipeline
|
32 |
from PIL import Image, ImageDraw, ImageFont
|
33 |
+
from transformers import pipeline, T5ForConditionalGeneration, T5Tokenizer
|
34 |
from refiners.fluxion.utils import manual_seed
|
35 |
from refiners.foundationals.latent_diffusion import Solver, solvers
|
36 |
from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler import (
|
|
|
38 |
UpscalerCheckpoints,
|
39 |
)
|
40 |
from datetime import datetime
|
41 |
+
from translate import Translator
|
42 |
+
|
43 |
+
model = T5ForConditionalGeneration.from_pretrained("t5-large")
|
44 |
+
tokenizer = T5Tokenizer.from_pretrained("t5-large")
|
45 |
|
|
|
|
|
46 |
|
47 |
def log(msg):
|
48 |
print(f'{datetime.now().time()} {msg}')
|
|
|
718 |
log(f'CALL translate')
|
719 |
if not from_lang:
|
720 |
from_lang = get_language(txt)
|
|
|
721 |
if(from_lang == to_lang):
|
722 |
log(f'RET translate with txt as {txt}')
|
723 |
return txt
|
724 |
+
|
725 |
+
translator = Translator(from_lang=from_lang,to_lang=to_lang)
|
726 |
+
translation = translator.translate(txt)
|
727 |
+
log(f'RET translate with translation as {translation}')
|
728 |
+
return translation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
729 |
|
730 |
@spaces.GPU(duration=300)
|
731 |
def handle_generation(artist,song,genre,lyrics):
|