Spaces:
Runtime error
Runtime error
Update app-backup.py
Browse files- app-backup.py +21 -28
app-backup.py
CHANGED
|
@@ -24,6 +24,9 @@ from transformers import T5EncoderModel, T5Tokenizer
|
|
| 24 |
# from optimum.quanto import freeze, qfloat8, quantize
|
| 25 |
from transformers import pipeline
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
class HFEmbedder(nn.Module):
|
| 28 |
def __init__(self, version: str, max_length: int, **hf_kwargs):
|
| 29 |
super().__init__()
|
|
@@ -746,12 +749,8 @@ model = Flux().to(dtype=torch.bfloat16, device="cuda")
|
|
| 746 |
result = model.load_state_dict(sd)
|
| 747 |
model_zero_init = False
|
| 748 |
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
ko_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 752 |
-
ja_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ja-en")
|
| 753 |
-
zh_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-zh-en")
|
| 754 |
-
|
| 755 |
|
| 756 |
|
| 757 |
@spaces.GPU
|
|
@@ -763,17 +762,14 @@ def generate_image(
|
|
| 763 |
):
|
| 764 |
translated_prompt = prompt
|
| 765 |
|
| 766 |
-
#
|
| 767 |
def contains_korean(text):
|
| 768 |
return any('\u3131' <= c <= '\u318E' or '\uAC00' <= c <= '\uD7A3' for c in text)
|
| 769 |
|
| 770 |
def contains_japanese(text):
|
| 771 |
return any('\u3040' <= c <= '\u309F' or '\u30A0' <= c <= '\u30FF' or '\u4E00' <= c <= '\u9FFF' for c in text)
|
| 772 |
|
| 773 |
-
|
| 774 |
-
return any('\u4e00' <= c <= '\u9fff' for c in text)
|
| 775 |
-
|
| 776 |
-
# 한글, 일본어, 중국어가 있으면 번역
|
| 777 |
if contains_korean(prompt):
|
| 778 |
translated_prompt = ko_translator(prompt, max_length=512)[0]['translation_text']
|
| 779 |
print(f"Translated Korean prompt: {translated_prompt}")
|
|
@@ -782,14 +778,6 @@ def generate_image(
|
|
| 782 |
translated_prompt = ja_translator(prompt, max_length=512)[0]['translation_text']
|
| 783 |
print(f"Translated Japanese prompt: {translated_prompt}")
|
| 784 |
prompt = translated_prompt
|
| 785 |
-
elif contains_chinese(prompt):
|
| 786 |
-
translated_prompt = zh_translator(prompt, max_length=512)[0]['translation_text']
|
| 787 |
-
print(f"Translated Chinese prompt: {translated_prompt}")
|
| 788 |
-
prompt = translated_prompt
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
|
| 794 |
if seed == 0:
|
| 795 |
seed = int(random.random() * 1000000)
|
|
@@ -855,10 +843,10 @@ footer {
|
|
| 855 |
|
| 856 |
def create_demo():
|
| 857 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 858 |
-
|
| 859 |
with gr.Row():
|
| 860 |
with gr.Column():
|
| 861 |
-
prompt = gr.Textbox(label="Prompt(
|
| 862 |
|
| 863 |
width = gr.Slider(minimum=128, maximum=2048, step=64, label="Width", value=768)
|
| 864 |
height = gr.Slider(minimum=128, maximum=2048, step=64, label="Height", value=768)
|
|
@@ -880,6 +868,17 @@ def create_demo():
|
|
| 880 |
with gr.Column():
|
| 881 |
output_image = gr.Image(label="Generated Image")
|
| 882 |
output_seed = gr.Text(label="Used Seed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 883 |
|
| 884 |
do_img2img.change(
|
| 885 |
fn=lambda x: [gr.update(visible=x), gr.update(visible=x), gr.update(visible=x)],
|
|
@@ -890,14 +889,8 @@ def create_demo():
|
|
| 890 |
generate_button.click(
|
| 891 |
fn=generate_image,
|
| 892 |
inputs=[prompt, width, height, guidance, inference_steps, seed, do_img2img, init_image, image2image_strength, resize_img],
|
| 893 |
-
outputs=[output_image, output_seed]
|
| 894 |
)
|
| 895 |
-
|
| 896 |
-
examples = [
|
| 897 |
-
"a tiny astronaut hatching from an egg on the moon",
|
| 898 |
-
"a cat holding a sign that says hello world",
|
| 899 |
-
"an anime illustration of a wiener schnitzel",
|
| 900 |
-
]
|
| 901 |
|
| 902 |
return demo
|
| 903 |
|
|
|
|
| 24 |
# from optimum.quanto import freeze, qfloat8, quantize
|
| 25 |
from transformers import pipeline
|
| 26 |
|
| 27 |
+
ko_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 28 |
+
ja_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ja-en")
|
| 29 |
+
|
| 30 |
class HFEmbedder(nn.Module):
|
| 31 |
def __init__(self, version: str, max_length: int, **hf_kwargs):
|
| 32 |
super().__init__()
|
|
|
|
| 749 |
result = model.load_state_dict(sd)
|
| 750 |
model_zero_init = False
|
| 751 |
|
| 752 |
+
# model = Flux().to(dtype=torch.bfloat16, device="cuda")
|
| 753 |
+
# result = model.load_state_dict(load_file("/storage/dev/nyanko/flux-dev/flux1-dev.sft"))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 754 |
|
| 755 |
|
| 756 |
@spaces.GPU
|
|
|
|
| 762 |
):
|
| 763 |
translated_prompt = prompt
|
| 764 |
|
| 765 |
+
# 한글 또는 일본어 문자 감지
|
| 766 |
def contains_korean(text):
|
| 767 |
return any('\u3131' <= c <= '\u318E' or '\uAC00' <= c <= '\uD7A3' for c in text)
|
| 768 |
|
| 769 |
def contains_japanese(text):
|
| 770 |
return any('\u3040' <= c <= '\u309F' or '\u30A0' <= c <= '\u30FF' or '\u4E00' <= c <= '\u9FFF' for c in text)
|
| 771 |
|
| 772 |
+
# 한글이나 일본어가 있으면 번역
|
|
|
|
|
|
|
|
|
|
| 773 |
if contains_korean(prompt):
|
| 774 |
translated_prompt = ko_translator(prompt, max_length=512)[0]['translation_text']
|
| 775 |
print(f"Translated Korean prompt: {translated_prompt}")
|
|
|
|
| 778 |
translated_prompt = ja_translator(prompt, max_length=512)[0]['translation_text']
|
| 779 |
print(f"Translated Japanese prompt: {translated_prompt}")
|
| 780 |
prompt = translated_prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 781 |
|
| 782 |
if seed == 0:
|
| 783 |
seed = int(random.random() * 1000000)
|
|
|
|
| 843 |
|
| 844 |
def create_demo():
|
| 845 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 846 |
+
gr.Markdown("# FLUXllama Multilingual")
|
| 847 |
with gr.Row():
|
| 848 |
with gr.Column():
|
| 849 |
+
prompt = gr.Textbox(label="Prompt(Supports English, Korean, and Japanese)", value="A cute and fluffy golden retriever puppy sitting upright, holding a neatly designed white sign with bold, colorful lettering that reads 'Have a Happy Day!' in cheerful fonts. The puppy has expressive, sparkling eyes, a happy smile, and fluffy ears slightly flopped. The background is a vibrant and sunny meadow with soft-focus flowers, glowing sunlight filtering through the trees, and a warm golden glow that enhances the joyful atmosphere. The sign is framed with small decorative flowers, adding a charming and wholesome touch. Ensure the text on the sign is clear and legible.")
|
| 850 |
|
| 851 |
width = gr.Slider(minimum=128, maximum=2048, step=64, label="Width", value=768)
|
| 852 |
height = gr.Slider(minimum=128, maximum=2048, step=64, label="Height", value=768)
|
|
|
|
| 868 |
with gr.Column():
|
| 869 |
output_image = gr.Image(label="Generated Image")
|
| 870 |
output_seed = gr.Text(label="Used Seed")
|
| 871 |
+
output_translated = gr.Text(label="Translated Prompt")
|
| 872 |
+
|
| 873 |
+
# Examples 컴포넌트 추가
|
| 874 |
+
gr.Examples(
|
| 875 |
+
examples=[
|
| 876 |
+
"a tiny astronaut hatching from an egg on the moon",
|
| 877 |
+
"썬글라스 착용한 귀여운 흰색 고양이가 'LOVE'라는 표지판을 들고있다",
|
| 878 |
+
"桜が流れる夜の街、照明",
|
| 879 |
+
],
|
| 880 |
+
inputs=prompt, # 예제가 입력될 컴포넌트 지정
|
| 881 |
+
)
|
| 882 |
|
| 883 |
do_img2img.change(
|
| 884 |
fn=lambda x: [gr.update(visible=x), gr.update(visible=x), gr.update(visible=x)],
|
|
|
|
| 889 |
generate_button.click(
|
| 890 |
fn=generate_image,
|
| 891 |
inputs=[prompt, width, height, guidance, inference_steps, seed, do_img2img, init_image, image2image_strength, resize_img],
|
| 892 |
+
outputs=[output_image, output_seed, output_translated]
|
| 893 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 894 |
|
| 895 |
return demo
|
| 896 |
|