Spaces:
Running
Running
fix: restore Flux 9B defaults, dual-mode client (simple + multi-step)
Browse files
backend/app/api/listing_free.py
CHANGED
|
@@ -99,8 +99,8 @@ async def auto_generate(body: dict):
|
|
| 99 |
openai_key = body.get("openai_key", "").strip()
|
| 100 |
product_info = body.get("product_info", "").strip()
|
| 101 |
wangp_url = body.get("wangp_url", "").strip()
|
| 102 |
-
model_choice = body.get("model_choice", "
|
| 103 |
-
resolution = body.get("resolution", "
|
| 104 |
steps = body.get("steps", 20)
|
| 105 |
guidance = body.get("guidance", 4)
|
| 106 |
ref_strength = body.get("ref_strength", 75)
|
|
|
|
| 99 |
openai_key = body.get("openai_key", "").strip()
|
| 100 |
product_info = body.get("product_info", "").strip()
|
| 101 |
wangp_url = body.get("wangp_url", "").strip()
|
| 102 |
+
model_choice = body.get("model_choice", "flux2_klein_9b")
|
| 103 |
+
resolution = body.get("resolution", "1088x1088")
|
| 104 |
steps = body.get("steps", 20)
|
| 105 |
guidance = body.get("guidance", 4)
|
| 106 |
ref_strength = body.get("ref_strength", 75)
|
backend/app/services/listing_free/wangp.py
CHANGED
|
@@ -9,12 +9,12 @@ except ImportError:
|
|
| 9 |
HAS_GRADIO = False
|
| 10 |
|
| 11 |
WANGP_URL = "https://fe91b5c9d1cfdfc08e.gradio.live/"
|
| 12 |
-
DEFAULT_MODEL = "
|
| 13 |
-
RESOLUTION = "
|
| 14 |
STEPS = 20
|
| 15 |
GUIDANCE = 4
|
| 16 |
REF_STRENGTH = 75
|
| 17 |
-
NEGATIVE_PROMPT = "mirror, reflection in mirror, text, words, letters, typography, captions, deformed hands, extra fingers, bad anatomy, blurry, low quality, watermark"
|
| 18 |
HUMAN_TYPES = {"thumbnail", "in_use", "lifestyle", "hero"}
|
| 19 |
BANNED_SCENE_WORDS = ["text", "typography", "overlay", "caption", "headline", "banner", "label",
|
| 20 |
"words", "letters", "writing", "sign", "title", "slogan", "font"]
|
|
@@ -45,15 +45,6 @@ class WanGPClient:
|
|
| 45 |
self._endpoints = []
|
| 46 |
return self.client
|
| 47 |
|
| 48 |
-
def _guess_ep(self):
|
| 49 |
-
self.ensure_client()
|
| 50 |
-
if not self._endpoints:
|
| 51 |
-
return "/predict"
|
| 52 |
-
for fav in ["/predict", "/run", "/generate", "/submit"]:
|
| 53 |
-
if fav in self._endpoints:
|
| 54 |
-
return fav
|
| 55 |
-
return self._endpoints[0]
|
| 56 |
-
|
| 57 |
def clean_scene(self, p):
|
| 58 |
segs = re.split(r'[,.]', p)
|
| 59 |
kept = []
|
|
@@ -111,59 +102,89 @@ class WanGPClient:
|
|
| 111 |
return True
|
| 112 |
return False
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
def generate_one(self, item, out_path, product_image, model_image=None):
|
| 115 |
-
product_refs = [handle_file(product_image)] if product_image and handle_file else []
|
| 116 |
-
person_refs = [handle_file(model_image)] if model_image and handle_file else []
|
| 117 |
prompt = self.clean_scene(item["scene_prompt"])
|
| 118 |
-
|
| 119 |
-
ep = self._guess_ep()
|
| 120 |
|
|
|
|
| 121 |
refs = list(product_refs)
|
| 122 |
-
|
| 123 |
-
if with_person and person_refs:
|
| 124 |
refs.extend(person_refs)
|
| 125 |
|
| 126 |
-
|
| 127 |
-
w, h = int(w), int(h)
|
| 128 |
-
|
| 129 |
for attempt in range(2):
|
| 130 |
try:
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
guidance_scale=self.guidance,
|
| 137 |
-
batch_size=1,
|
| 138 |
-
api_name=ep,
|
| 139 |
-
)
|
| 140 |
break
|
| 141 |
except Exception as e:
|
| 142 |
msg = str(e)
|
| 143 |
-
# try alternate param names
|
| 144 |
-
try:
|
| 145 |
-
res = wan.predict(
|
| 146 |
-
prompt=prompt,
|
| 147 |
-
negative_prompt=self.negative_prompt,
|
| 148 |
-
width=w, height=h,
|
| 149 |
-
steps=self.steps,
|
| 150 |
-
guidance=self.guidance,
|
| 151 |
-
api_name=ep,
|
| 152 |
-
)
|
| 153 |
-
break
|
| 154 |
-
except Exception:
|
| 155 |
-
pass
|
| 156 |
if "not in the list of choices" in msg:
|
| 157 |
raise
|
| 158 |
if attempt == 0 and ("timed out" in msg or "Timeout" in msg):
|
| 159 |
time.sleep(3)
|
| 160 |
continue
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
| 167 |
|
| 168 |
ps = self.img_paths(res)
|
| 169 |
if not ps:
|
|
|
|
| 9 |
HAS_GRADIO = False
|
| 10 |
|
| 11 |
WANGP_URL = "https://fe91b5c9d1cfdfc08e.gradio.live/"
|
| 12 |
+
DEFAULT_MODEL = "flux2_klein_9b"
|
| 13 |
+
RESOLUTION = "1088x1088"
|
| 14 |
STEPS = 20
|
| 15 |
GUIDANCE = 4
|
| 16 |
REF_STRENGTH = 75
|
| 17 |
+
NEGATIVE_PROMPT = "mirror, reflection in mirror, standing in front of mirror, bathroom mirror, text, words, letters, typography, captions, deformed hands, extra fingers, bad anatomy, blurry, low quality, watermark"
|
| 18 |
HUMAN_TYPES = {"thumbnail", "in_use", "lifestyle", "hero"}
|
| 19 |
BANNED_SCENE_WORDS = ["text", "typography", "overlay", "caption", "headline", "banner", "label",
|
| 20 |
"words", "letters", "writing", "sign", "title", "slogan", "font"]
|
|
|
|
| 45 |
self._endpoints = []
|
| 46 |
return self.client
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
def clean_scene(self, p):
|
| 49 |
segs = re.split(r'[,.]', p)
|
| 50 |
kept = []
|
|
|
|
| 102 |
return True
|
| 103 |
return False
|
| 104 |
|
| 105 |
+
def _try_predict(self, prompt, refs):
|
| 106 |
+
"""Try simple single-call predict."""
|
| 107 |
+
wan = self.ensure_client()
|
| 108 |
+
w, h = self.resolution.split("x")
|
| 109 |
+
w, h = int(w), int(h)
|
| 110 |
+
ep = "/predict"
|
| 111 |
+
if self._endpoints:
|
| 112 |
+
for fav in ["/predict", "/run", "/generate", "/submit"]:
|
| 113 |
+
if fav in self._endpoints:
|
| 114 |
+
ep = fav
|
| 115 |
+
break
|
| 116 |
+
else:
|
| 117 |
+
ep = self._endpoints[0]
|
| 118 |
+
for params in [
|
| 119 |
+
dict(prompt=prompt, negative_prompt=self.negative_prompt, width=w, height=h,
|
| 120 |
+
num_inference_steps=self.steps, guidance_scale=self.guidance, batch_size=1,
|
| 121 |
+
image=refs[0] if refs else None, api_name=ep),
|
| 122 |
+
dict(prompt=prompt, negative_prompt=self.negative_prompt, width=w, height=h,
|
| 123 |
+
steps=self.steps, guidance=self.guidance, api_name=ep),
|
| 124 |
+
dict(prompt=prompt, api_name=ep),
|
| 125 |
+
]:
|
| 126 |
+
try:
|
| 127 |
+
return wan.predict(**{k: v for k, v in params.items() if v is not None})
|
| 128 |
+
except Exception:
|
| 129 |
+
continue
|
| 130 |
+
return None
|
| 131 |
+
|
| 132 |
+
def _try_multi_step(self, prompt, refs, has_person):
|
| 133 |
+
"""Original multi-step (Flux Space style)."""
|
| 134 |
+
wan = self.ensure_client()
|
| 135 |
+
vpt = "I" if refs else ""
|
| 136 |
+
save_args = dict(
|
| 137 |
+
prompt=prompt, negative_prompt=self.negative_prompt, resolution=self.resolution, seed=-1,
|
| 138 |
+
num_inference_steps=self.steps, guidance_scale=self.guidance, batch_size=1, image_refs=refs,
|
| 139 |
+
image_refs_relative_size=self.ref_strength, video_prompt_type=vpt, image_prompt_type="",
|
| 140 |
+
control_net_weight=1, denoising_strength=1,
|
| 141 |
+
image_mask_guide={"background": None, "layers": [], "composite": None}, model_mode=None,
|
| 142 |
+
video_source=None, video_guide=None, image_guide=None, video_mask=None, image_mask=None,
|
| 143 |
+
audio_guide=None, audio_guide2=None, custom_guide=None, audio_source=None,
|
| 144 |
+
replace_voice_sample=None, replace_voice_sample2=None,
|
| 145 |
+
custom_setting_dropdown_1=None, custom_setting_dropdown_2=None,
|
| 146 |
+
custom_setting_dropdown_3=None, custom_setting_dropdown_4=None,
|
| 147 |
+
custom_setting_dropdown_5=None, api_name="/save_inputs_1"
|
| 148 |
+
)
|
| 149 |
+
wan.predict(**save_args)
|
| 150 |
+
wan.predict(current_gallery_tab=0, model_choice=self.model, api_name="/process_prompt_and_add_tasks")
|
| 151 |
+
wan.predict(api_name="/process_tasks")
|
| 152 |
+
return wan.predict(api_name="/finalize_generation")
|
| 153 |
+
|
| 154 |
def generate_one(self, item, out_path, product_image, model_image=None):
|
| 155 |
+
product_refs = [{"image": handle_file(product_image)}] if product_image and handle_file else []
|
| 156 |
+
person_refs = [{"image": handle_file(model_image)}] if model_image and handle_file else []
|
| 157 |
prompt = self.clean_scene(item["scene_prompt"])
|
| 158 |
+
self.ensure_client()
|
|
|
|
| 159 |
|
| 160 |
+
has_person = item.get("type", "") in HUMAN_TYPES
|
| 161 |
refs = list(product_refs)
|
| 162 |
+
if has_person and person_refs:
|
|
|
|
| 163 |
refs.extend(person_refs)
|
| 164 |
|
| 165 |
+
res = None
|
|
|
|
|
|
|
| 166 |
for attempt in range(2):
|
| 167 |
try:
|
| 168 |
+
# Try simple predict first
|
| 169 |
+
res = self._try_predict(prompt, refs)
|
| 170 |
+
if res is None:
|
| 171 |
+
# Fall back to multi-step
|
| 172 |
+
res = self._try_multi_step(prompt, refs, has_person)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
break
|
| 174 |
except Exception as e:
|
| 175 |
msg = str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
if "not in the list of choices" in msg:
|
| 177 |
raise
|
| 178 |
if attempt == 0 and ("timed out" in msg or "Timeout" in msg):
|
| 179 |
time.sleep(3)
|
| 180 |
continue
|
| 181 |
+
if attempt == 0:
|
| 182 |
+
try:
|
| 183 |
+
res = self._try_multi_step(prompt, refs, has_person)
|
| 184 |
+
break
|
| 185 |
+
except Exception:
|
| 186 |
+
pass
|
| 187 |
+
raise
|
| 188 |
|
| 189 |
ps = self.img_paths(res)
|
| 190 |
if not ps:
|
frontend/src/pages/ListingFree.jsx
CHANGED
|
@@ -3,16 +3,15 @@ import { IcImage, IcUpload, IcDownload, IcRefresh, IcStar } from "../components/
|
|
| 3 |
|
| 4 |
const RESOLUTIONS = [
|
| 5 |
{ label: "1088x1088 (Square)", value: "1088x1088" },
|
|
|
|
| 6 |
{ label: "1024x1024", value: "1024x1024" },
|
| 7 |
-
{ label: "
|
| 8 |
-
{ label: "1216x832", value: "1216x832" },
|
| 9 |
-
{ label: "720x720", value: "720x720" },
|
| 10 |
];
|
| 11 |
const MODELS = [
|
| 12 |
-
{ label: "
|
| 13 |
-
{ label: "Klein
|
| 14 |
-
{ label: "Flux Schnell", value: "flux_schnell" },
|
| 15 |
{ label: "Flux 1.1 Pro", value: "flux_1.1_pro" },
|
|
|
|
| 16 |
];
|
| 17 |
|
| 18 |
export default function ListingFree() {
|
|
@@ -32,8 +31,8 @@ export default function ListingFree() {
|
|
| 32 |
|
| 33 |
const [wangpUrl, setWangpUrl] = useState(() => { try { return localStorage.getItem("tnt_wangp_url") || "https://fe91b5c9d1cfdfc08e.gradio.live/"; } catch { return "https://fe91b5c9d1cfdfc08e.gradio.live/"; }});
|
| 34 |
const [openaiKey, setOpenaiKey] = useState(() => { try { return localStorage.getItem("tnt_openai_key") || ""; } catch { return ""; }});
|
| 35 |
-
const [modelChoice, setModelChoice] = useState("
|
| 36 |
-
const [resolution, setResolution] = useState("
|
| 37 |
const [steps, setSteps] = useState(20);
|
| 38 |
const [guidance, setGuidance] = useState(4);
|
| 39 |
const [refStrength, setRefStrength] = useState(75);
|
|
|
|
| 3 |
|
| 4 |
const RESOLUTIONS = [
|
| 5 |
{ label: "1088x1088 (Square)", value: "1088x1088" },
|
| 6 |
+
{ label: "1088x1920 (Portrait)", value: "1088x1920" },
|
| 7 |
{ label: "1024x1024", value: "1024x1024" },
|
| 8 |
+
{ label: "1280x720 (Landscape)", value: "1280x720" },
|
|
|
|
|
|
|
| 9 |
];
|
| 10 |
const MODELS = [
|
| 11 |
+
{ label: "Flux2 Klein 9B", value: "flux2_klein_9b" },
|
| 12 |
+
{ label: "Flux2 Klein 4B", value: "flux2_klein_4b" },
|
|
|
|
| 13 |
{ label: "Flux 1.1 Pro", value: "flux_1.1_pro" },
|
| 14 |
+
{ label: "Flux Schnell", value: "flux_schnell" },
|
| 15 |
];
|
| 16 |
|
| 17 |
export default function ListingFree() {
|
|
|
|
| 31 |
|
| 32 |
const [wangpUrl, setWangpUrl] = useState(() => { try { return localStorage.getItem("tnt_wangp_url") || "https://fe91b5c9d1cfdfc08e.gradio.live/"; } catch { return "https://fe91b5c9d1cfdfc08e.gradio.live/"; }});
|
| 33 |
const [openaiKey, setOpenaiKey] = useState(() => { try { return localStorage.getItem("tnt_openai_key") || ""; } catch { return ""; }});
|
| 34 |
+
const [modelChoice, setModelChoice] = useState("flux2_klein_9b");
|
| 35 |
+
const [resolution, setResolution] = useState("1088x1088");
|
| 36 |
const [steps, setSteps] = useState(20);
|
| 37 |
const [guidance, setGuidance] = useState(4);
|
| 38 |
const [refStrength, setRefStrength] = useState(75);
|