aiqcamp commited on
Commit
d2f711c
ยท
verified ยท
1 Parent(s): 1c71c6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -29
app.py CHANGED
@@ -15,8 +15,8 @@ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
15
 
16
  # ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ฐ LoRA ์„ค์ •
17
  base_model = "black-forest-labs/FLUX.1-dev"
18
- model_lora_repo = "Motas/Flux_Fashion_Photography_Style" # ํŒจ์…˜ ๋ชจ๋ธ LoRA
19
- clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA" # ์˜๋ฅ˜ LoRA
20
 
21
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
22
  pipe.to("cuda")
@@ -38,7 +38,9 @@ clothes_examples = [
38
 
39
  @spaces.GPU()
40
  def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
41
- # ํ•œ๊ธ€ ๊ฐ์ง€ ๋ฐ ๋ฒˆ์—ญ
 
 
42
  def contains_korean(text):
43
  return any(ord('๊ฐ€') <= ord(char) <= ord('ํžฃ') for char in text)
44
 
@@ -48,7 +50,6 @@ def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width
48
  else:
49
  actual_prompt = prompt
50
 
51
- # ๋ชจ๋“œ์— ๋”ฐ๋ฅธ LoRA ๋ฐ ํŠธ๋ฆฌ๊ฑฐ์›Œ๋“œ ์„ค์ •
52
  if mode == "ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ":
53
  pipe.load_lora_weights(model_lora_repo)
54
  trigger_word = "fashion photography, professional model"
@@ -60,12 +61,6 @@ def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width
60
  seed = random.randint(0, MAX_SEED)
61
  generator = torch.Generator(device="cuda").manual_seed(seed)
62
 
63
- progress(0, "Starting fashion generation...")
64
-
65
- for i in range(1, steps + 1):
66
- if i % (steps // 10) == 0:
67
- progress(i / steps * 100, f"Processing step {i} of {steps}...")
68
-
69
  image = pipe(
70
  prompt=f"{actual_prompt} {trigger_word}",
71
  num_inference_steps=steps,
@@ -76,48 +71,43 @@ def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width
76
  joint_attention_kwargs={"scale": lora_scale},
77
  ).images[0]
78
 
79
- progress(100, "Completed!")
80
  return image, seed
81
 
82
- def update_examples(mode):
83
- if mode == "ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ":
84
- return gr.Examples(examples=model_examples)
85
- else:
86
- return gr.Examples(examples=clothes_examples)
87
-
88
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as app:
89
  gr.Markdown("# ๐ŸŽญ Fashion AI Studio")
90
  gr.Markdown("AI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒจ์…˜ ๋ชจ๋ธ๊ณผ ์˜๋ฅ˜๋ฅผ ์ƒ์„ฑํ•ด๋ณด์„ธ์š”")
91
 
92
  with gr.Column():
93
- # ๋ชจ๋“œ ์„ ํƒ
94
  mode = gr.Radio(
95
  choices=["ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ", "ํŒจ์…˜ ์˜๋ฅ˜ ์ƒ์„ฑ"],
96
  label="์ƒ์„ฑ ๋ชจ๋“œ",
97
  value="ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ"
98
  )
99
 
100
- # ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ
101
  prompt = gr.TextArea(
102
  label="โœ๏ธ ํŒจ์…˜ ์„ค๋ช… (ํ•œ๊ธ€ ๋˜๋Š” ์˜์–ด)",
103
  placeholder="ํŒจ์…˜ ๋ชจ๋ธ์ด๋‚˜ ์˜๋ฅ˜๋ฅผ ์„ค๋ช…ํ•˜์„ธ์š”...",
104
  lines=3
105
  )
106
 
107
- # ์˜ˆ์‹œ ์„น์…˜
108
- with gr.Column() as example_container:
109
- examples = gr.Examples(
110
  examples=model_examples,
111
  inputs=prompt,
112
- label="์˜ˆ์‹œ ํ”„๋กฌํ”„ํŠธ"
 
 
 
 
 
 
 
113
  )
114
 
115
- # ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€
116
  result = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
117
-
118
  generate_button = gr.Button("๐Ÿš€ ์ด๋ฏธ์ง€ ์ƒ์„ฑ")
119
 
120
- # ๊ณ ๊ธ‰ ์„ค์ •
121
  with gr.Accordion("๐ŸŽจ ๊ณ ๊ธ‰ ์„ค์ •", open=False):
122
  with gr.Row():
123
  cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7.0)
@@ -132,11 +122,16 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as app:
132
  randomize_seed = gr.Checkbox(True, label="์‹œ๋“œ ๋žœ๋คํ™”")
133
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, value=42)
134
 
135
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
 
 
 
 
 
136
  mode.change(
137
- fn=update_examples,
138
  inputs=[mode],
139
- outputs=[examples]
140
  )
141
 
142
  generate_button.click(
 
15
 
16
  # ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ฐ LoRA ์„ค์ •
17
  base_model = "black-forest-labs/FLUX.1-dev"
18
+ model_lora_repo = "Motas/Flux_Fashion_Photography_Style"
19
+ clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA"
20
 
21
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
22
  pipe.to("cuda")
 
38
 
39
  @spaces.GPU()
40
  def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
41
+ if not prompt:
42
+ return None, seed
43
+
44
  def contains_korean(text):
45
  return any(ord('๊ฐ€') <= ord(char) <= ord('ํžฃ') for char in text)
46
 
 
50
  else:
51
  actual_prompt = prompt
52
 
 
53
  if mode == "ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ":
54
  pipe.load_lora_weights(model_lora_repo)
55
  trigger_word = "fashion photography, professional model"
 
61
  seed = random.randint(0, MAX_SEED)
62
  generator = torch.Generator(device="cuda").manual_seed(seed)
63
 
 
 
 
 
 
 
64
  image = pipe(
65
  prompt=f"{actual_prompt} {trigger_word}",
66
  num_inference_steps=steps,
 
71
  joint_attention_kwargs={"scale": lora_scale},
72
  ).images[0]
73
 
 
74
  return image, seed
75
 
 
 
 
 
 
 
76
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as app:
77
  gr.Markdown("# ๐ŸŽญ Fashion AI Studio")
78
  gr.Markdown("AI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒจ์…˜ ๋ชจ๋ธ๊ณผ ์˜๋ฅ˜๋ฅผ ์ƒ์„ฑํ•ด๋ณด์„ธ์š”")
79
 
80
  with gr.Column():
 
81
  mode = gr.Radio(
82
  choices=["ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ", "ํŒจ์…˜ ์˜๋ฅ˜ ์ƒ์„ฑ"],
83
  label="์ƒ์„ฑ ๋ชจ๋“œ",
84
  value="ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ"
85
  )
86
 
 
87
  prompt = gr.TextArea(
88
  label="โœ๏ธ ํŒจ์…˜ ์„ค๋ช… (ํ•œ๊ธ€ ๋˜๋Š” ์˜์–ด)",
89
  placeholder="ํŒจ์…˜ ๋ชจ๋ธ์ด๋‚˜ ์˜๋ฅ˜๋ฅผ ์„ค๋ช…ํ•˜์„ธ์š”...",
90
  lines=3
91
  )
92
 
93
+ # ์˜ˆ์‹œ ์„น์…˜์„ ๋ชจ๋“œ๋ณ„๋กœ ๋ถ„๋ฆฌ
94
+ with gr.Column(visible=True) as model_examples_container:
95
+ gr.Examples(
96
  examples=model_examples,
97
  inputs=prompt,
98
+ label="ํŒจ์…˜ ๋ชจ๋ธ ์˜ˆ์‹œ"
99
+ )
100
+
101
+ with gr.Column(visible=False) as clothes_examples_container:
102
+ gr.Examples(
103
+ examples=clothes_examples,
104
+ inputs=prompt,
105
+ label="ํŒจ์…˜ ์˜๋ฅ˜ ์˜ˆ์‹œ"
106
  )
107
 
 
108
  result = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
 
109
  generate_button = gr.Button("๐Ÿš€ ์ด๋ฏธ์ง€ ์ƒ์„ฑ")
110
 
 
111
  with gr.Accordion("๐ŸŽจ ๊ณ ๊ธ‰ ์„ค์ •", open=False):
112
  with gr.Row():
113
  cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7.0)
 
122
  randomize_seed = gr.Checkbox(True, label="์‹œ๋“œ ๋žœ๋คํ™”")
123
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, value=42)
124
 
125
+ def update_visibility(mode):
126
+ return (
127
+ gr.update(visible=(mode == "ํŒจ์…˜ ๋ชจ๋ธ ์ƒ์„ฑ")),
128
+ gr.update(visible=(mode == "ํŒจ์…˜ ์˜๋ฅ˜ ์ƒ์„ฑ"))
129
+ )
130
+
131
  mode.change(
132
+ fn=update_visibility,
133
  inputs=[mode],
134
+ outputs=[model_examples_container, clothes_examples_container]
135
  )
136
 
137
  generate_button.click(