Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,31 @@ import gradio as gr
|
|
15 |
import os
|
16 |
from huggingface_hub import login
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Download checkpoints
|
20 |
snapshot_download(repo_id="franciszzj/Leffa", local_dir="./ckpts")
|
@@ -41,26 +66,7 @@ pt_model = LeffaModel(
|
|
41 |
)
|
42 |
pt_inference = LeffaInference(model=pt_model)
|
43 |
|
44 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
45 |
-
if HF_TOKEN is None:
|
46 |
-
raise ValueError("Please set the HF_TOKEN environment variable")
|
47 |
-
login(token=HF_TOKEN)
|
48 |
|
49 |
-
# FLUX ๋ชจ๋ธ ์ด๊ธฐํ ๋ถ๋ถ ์์
|
50 |
-
fashion_pipe = DiffusionPipeline.from_pretrained(
|
51 |
-
base_model,
|
52 |
-
torch_dtype=torch.bfloat16,
|
53 |
-
use_auth_token=HF_TOKEN # ์ธ์ฆ ํ ํฐ ์ถ๊ฐ
|
54 |
-
)
|
55 |
-
fashion_pipe.to("cuda")
|
56 |
-
|
57 |
-
# LoRA ๋ก๋ฉ ํจ์ ์์
|
58 |
-
def load_lora(pipe, repo_id):
|
59 |
-
pipe.load_lora_weights(
|
60 |
-
repo_id,
|
61 |
-
use_auth_token=HF_TOKEN
|
62 |
-
)
|
63 |
-
return pipe
|
64 |
|
65 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
66 |
base_model = "black-forest-labs/FLUX.1-dev"
|
@@ -70,17 +76,17 @@ clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA"
|
|
70 |
fashion_pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
71 |
fashion_pipe.to("cuda")
|
72 |
|
|
|
|
|
|
|
73 |
@spaces.GPU()
|
74 |
def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
75 |
-
# ํ๊ธ ๊ฐ์ง ๋ฐ ๋ฒ์ญ
|
76 |
-
def contains_korean(text):
|
77 |
-
return any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text)
|
78 |
-
|
79 |
if contains_korean(prompt):
|
80 |
translated = translator(prompt)[0]['translation_text']
|
81 |
actual_prompt = translated
|
82 |
else:
|
83 |
actual_prompt = prompt
|
|
|
84 |
|
85 |
# ๋ชจ๋์ ๋ฐ๋ฅธ LoRA ๋ก๋ฉ ๋ฐ ํธ๋ฆฌ๊ฑฐ์๋ ์ค์
|
86 |
if mode == "Generate Model":
|
|
|
15 |
import os
|
16 |
from huggingface_hub import login
|
17 |
|
18 |
+
# HF_TOKEN ์ค์ ์งํ์ ์ถ๊ฐ
|
19 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
20 |
+
if HF_TOKEN is None:
|
21 |
+
raise ValueError("Please set the HF_TOKEN environment variable")
|
22 |
+
login(token=HF_TOKEN)
|
23 |
+
|
24 |
+
# ๋ชจ๋ธ ์ค์
|
25 |
+
base_model = "black-forest-labs/FLUX.1-dev"
|
26 |
+
model_lora_repo = "Motas/Flux_Fashion_Photography_Style"
|
27 |
+
clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA"
|
28 |
+
|
29 |
+
# FLUX ๋ชจ๋ธ ์ด๊ธฐํ (ํ ๋ฒ๋ง)
|
30 |
+
fashion_pipe = DiffusionPipeline.from_pretrained(
|
31 |
+
base_model,
|
32 |
+
torch_dtype=torch.bfloat16,
|
33 |
+
use_auth_token=HF_TOKEN
|
34 |
+
)
|
35 |
+
fashion_pipe.to("cuda")
|
36 |
+
|
37 |
+
# ๋ฒ์ญ๊ธฐ ์ด๊ธฐํ
|
38 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
39 |
+
|
40 |
+
# ์์ ์ ์ ์ถ๊ฐ
|
41 |
+
import random
|
42 |
+
MAX_SEED = 2**32 - 1
|
43 |
|
44 |
# Download checkpoints
|
45 |
snapshot_download(repo_id="franciszzj/Leffa", local_dir="./ckpts")
|
|
|
66 |
)
|
67 |
pt_inference = LeffaInference(model=pt_model)
|
68 |
|
|
|
|
|
|
|
|
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
72 |
base_model = "black-forest-labs/FLUX.1-dev"
|
|
|
76 |
fashion_pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
77 |
fashion_pipe.to("cuda")
|
78 |
|
79 |
+
def contains_korean(text):
|
80 |
+
return any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text)
|
81 |
+
|
82 |
@spaces.GPU()
|
83 |
def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
|
|
84 |
if contains_korean(prompt):
|
85 |
translated = translator(prompt)[0]['translation_text']
|
86 |
actual_prompt = translated
|
87 |
else:
|
88 |
actual_prompt = prompt
|
89 |
+
|
90 |
|
91 |
# ๋ชจ๋์ ๋ฐ๋ฅธ LoRA ๋ก๋ฉ ๋ฐ ํธ๋ฆฌ๊ฑฐ์๋ ์ค์
|
92 |
if mode == "Generate Model":
|