aifeifei798 commited on
Commit
559ce8f
·
verified ·
1 Parent(s): 902134a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -5
app.py CHANGED
@@ -10,6 +10,8 @@ from diffusers import (
10
  )
11
  from huggingface_hub import hf_hub_download
12
 
 
 
13
  MAX_SEED = np.iinfo(np.int32).max
14
  MAX_IMAGE_SIZE = 2048
15
 
@@ -26,7 +28,10 @@ def feifeimodload():
26
  hf_hub_download("aifeifei798/feifei-flux-lora-v1.1", "feifei-v1.1.safetensors"),
27
  adapter_name="feifei",
28
  )
29
-
 
 
 
30
  pipe.vae.enable_slicing()
31
  pipe.vae.enable_tiling()
32
  torch.cuda.empty_cache()
@@ -35,7 +40,42 @@ def feifeimodload():
35
  pipe = feifeimodload()
36
 
37
  @spaces.GPU()
38
- def infer(prompt="", seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, guidancescale=3.5, num_feifei=0.35, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  if randomize_seed:
40
  seed = random.randint(0, MAX_SEED)
41
  generator = torch.Generator().manual_seed(seed)
@@ -94,8 +134,15 @@ with gr.Blocks(css=css) as demo:
94
  container=False,
95
  )
96
  run_button = gr.Button("Run")
 
 
 
 
 
 
 
97
  result = gr.Image(label="Result", show_label=False,height=520)
98
-
99
  with gr.Accordion("Advanced Settings", open=False):
100
 
101
  seed = gr.Slider(
@@ -152,7 +199,15 @@ with gr.Blocks(css=css) as demo:
152
  step=0.05,
153
  value=0.45,
154
  )
155
-
 
 
 
 
 
 
 
 
156
 
157
  gr.Examples(
158
  examples = examples,
@@ -165,7 +220,7 @@ with gr.Blocks(css=css) as demo:
165
  gr.on(
166
  triggers=[run_button.click, prompt.submit],
167
  fn = infer,
168
- inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps, guidancescale, num_feifei],
169
  outputs = [result, seed]
170
  )
171
 
 
10
  )
11
  from huggingface_hub import hf_hub_download
12
 
13
+ import config
14
+ styles_name = [style["name"] for style in config.style_list]
15
  MAX_SEED = np.iinfo(np.int32).max
16
  MAX_IMAGE_SIZE = 2048
17
 
 
28
  hf_hub_download("aifeifei798/feifei-flux-lora-v1.1", "feifei-v1.1.safetensors"),
29
  adapter_name="feifei",
30
  )
31
+ pipe.load_lora_weights(
32
+ hf_hub_download("aifeifei798/sldr_flux_nsfw_v2-studio", "sldr_flux_nsfw_v2-studio.safetensors"),
33
+ adapter_name="sldr_flux_nsfw_v2",
34
+ )
35
  pipe.vae.enable_slicing()
36
  pipe.vae.enable_tiling()
37
  torch.cuda.empty_cache()
 
40
  pipe = feifeimodload()
41
 
42
  @spaces.GPU()
43
+ def infer(prompt="", styles_Radio="(None)", Expansion_select=False, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, guidancescale=3.5, num_feifei=0.35, nsfw_select=False, nsfw_slider=1, progress=gr.Progress(track_tqdm=True)):
44
+
45
+ if nsfw_select:
46
+ pipe.set_adapters(
47
+ ["feifei", "sldr_flux_nsfw_v2"],
48
+ adapter_weights=[num_feifei,nsfw_slider],
49
+ )
50
+ pipe.fuse_lora(
51
+ adapter_name=["feifei", "sldr_flux_nsfw_v2"],
52
+ lora_scale=1.0,
53
+ )
54
+ else:
55
+ pipe.set_adapters(
56
+ ["feifei"],
57
+ adapter_weights=[num_feifei],
58
+ )
59
+ pipe.fuse_lora(
60
+ adapter_name=["feifei"],
61
+ lora_scale=1.0,
62
+ )
63
+
64
+ if Expansion_select:
65
+ # Define the replacement string
66
+ replacement = " feifei, A beautiful, 18 yo kpop idol, large-busted Japanese slim girl, with light makeup, gazing deeply into the camera, "
67
+
68
+ # Perform the replacements with re.IGNORECASE
69
+ prompt = re.sub(r"girl", replacement, prompt, flags=re.IGNORECASE)
70
+ prompt = re.sub(r"young woman", replacement, prompt, flags=re.IGNORECASE)
71
+ prompt = re.sub(r"woman", replacement, prompt, flags=re.IGNORECASE)
72
+ prompt = re.sub(r"model", replacement, prompt, flags=re.IGNORECASE)
73
+
74
+ if styles_Radio:
75
+ style_name = styles_Radio
76
+ for style in config.style_list:
77
+ if style["name"] == style_name:
78
+ prompt = style["prompt"].replace("{prompt}", prompt)
79
  if randomize_seed:
80
  seed = random.randint(0, MAX_SEED)
81
  generator = torch.Generator().manual_seed(seed)
 
134
  container=False,
135
  )
136
  run_button = gr.Button("Run")
137
+ with gr.Row():
138
+ styles_Radio = gr.Dropdown(
139
+ styles_name,
140
+ label="Styles",
141
+ multiselect=False,
142
+ value="(None)",
143
+ )
144
  result = gr.Image(label="Result", show_label=False,height=520)
145
+ Expansion_select = gr.Checkbox(label="FeiFei Expansion")
146
  with gr.Accordion("Advanced Settings", open=False):
147
 
148
  seed = gr.Slider(
 
199
  step=0.05,
200
  value=0.45,
201
  )
202
+ with gr.Row():
203
+ nsfw_select = gr.Checkbox(label="NSFW")
204
+ nsfw_slider = gr.Slider(
205
+ label="NSFW",
206
+ minimum=0,
207
+ maximum=2,
208
+ step=0.05,
209
+ value=0.75,
210
+ )
211
 
212
  gr.Examples(
213
  examples = examples,
 
220
  gr.on(
221
  triggers=[run_button.click, prompt.submit],
222
  fn = infer,
223
+ inputs = [prompt, styles_Radio, Expansion_select, seed, randomize_seed, width, height, num_inference_steps, guidancescale, num_feifei, nsfw_select, nsfw_slider],
224
  outputs = [result, seed]
225
  )
226