Spaces:
ginipick
/
Running on Zero

ginipick commited on
Commit
31c6398
ยท
verified ยท
1 Parent(s): 80cec7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -23
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":