pormungtai commited on
Commit
ed39ab2
·
verified ·
1 Parent(s): 503ae1b

Add Prompt Builder: fill-in-the-blank form that assembles a prompt

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py CHANGED
@@ -151,6 +151,25 @@ def reload_registry():
151
  )
152
 
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  # ---------------------------------------------------------------------------
155
  # Layout (mirrors the FLUX LoRA DLC reference UI)
156
  # ---------------------------------------------------------------------------
@@ -171,6 +190,29 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft(primary_hue="blue"),
171
  )
172
  gen_btn = gr.Button("Generate", variant="primary", scale=1, elem_id="gen-btn")
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  # State: ordered list of model ids (matches gallery order) + current selection.
175
  ids_state = gr.State(model_ids(MODELS))
176
  selected_id = gr.State(MODELS[0]["id"] if MODELS else None)
@@ -242,6 +284,12 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft(primary_hue="blue"),
242
  reload_registry,
243
  outputs=[model_gallery, ids_state, selected_id, reload_status],
244
  )
 
 
 
 
 
 
245
 
246
  gen_inputs = [selected_id, mode_radio, prompt, negative_prompt, ref_image,
247
  steps, guidance, denoise, ip_scale, width, height, seed, randomize,
 
151
  )
152
 
153
 
154
+ def build_prompt(subject, age, ethnicity, body, hair, eyes, outfit, pose,
155
+ expression, scene, lighting, shot):
156
+ """Assemble form fields into a prompt. Thai values are fine — the auto-translator
157
+ turns the whole thing into English at generate time."""
158
+ parts = []
159
+ who = (subject or "ผู้หญิง").strip()
160
+ if ethnicity and ethnicity.strip():
161
+ who = f"{ethnicity.strip()} {who}"
162
+ if age and str(age).strip():
163
+ who = f"{who} อายุ {str(age).strip()} ปี"
164
+ parts.append(who)
165
+ for v in (body, hair, eyes, outfit, pose, expression, scene, lighting, shot):
166
+ if v and str(v).strip():
167
+ parts.append(str(v).strip())
168
+ thai = ", ".join(parts)
169
+ # English quality suffix (kept in English; the model's negative handles the rest).
170
+ return thai + ", photorealistic, masterpiece, best quality, ultra-detailed, sharp focus"
171
+
172
+
173
  # ---------------------------------------------------------------------------
174
  # Layout (mirrors the FLUX LoRA DLC reference UI)
175
  # ---------------------------------------------------------------------------
 
190
  )
191
  gen_btn = gr.Button("Generate", variant="primary", scale=1, elem_id="gen-btn")
192
 
193
+ # ---- Prompt Builder: fill blanks instead of writing sentences ----
194
+ with gr.Accordion("📝 ตัวช่วยสร้าง prompt / Prompt Builder — กรอกช่อง ไม่ต้องเขียนประโยค",
195
+ open=False):
196
+ gr.Markdown("กรอกเฉพาะช่องที่ต้องการ (เป็นภาษาไทยได้) แล้วกดปุ่มด้านล่าง "
197
+ "ระบบจะประกอบเป็น prompt ให้ในช่องด้านบน · เว้นว่างช่องที่ไม่ใช้ได้")
198
+ with gr.Row():
199
+ b_subject = gr.Textbox(label="ใคร / ตัวละคร", value="ผู้หญิง")
200
+ b_age = gr.Textbox(label="อายุ", placeholder="เช่น 25")
201
+ b_ethnicity = gr.Textbox(label="เชื้อชาติ / สัญชาติ", placeholder="เช่น เกาหลี, ไทย")
202
+ with gr.Row():
203
+ b_body = gr.Textbox(label="รูปร่าง / สัดส่วน", placeholder="เช่น ผอมสูง, ทรงนาฬิกาทราย")
204
+ b_hair = gr.Textbox(label="ทรงผม / สีผม", placeholder="เช่น ผมยาวสีดำ, ผมบลอนด์")
205
+ b_eyes = gr.Textbox(label="สีตา", placeholder="เช่น ตาสีน้ำตาล")
206
+ with gr.Row():
207
+ b_outfit = gr.Textbox(label="ชุด / เสื้อผ้า", placeholder="เช่น เดรสสีขาว, ชุดนักเรียน")
208
+ b_pose = gr.Textbox(label="ท่าโพส", placeholder="เช่น ยืนมือเท้าเอว, นั่ง")
209
+ b_expr = gr.Textbox(label="สีหน้า / อารมณ์", placeholder="เช่น ยิ้มอ่อนๆ")
210
+ with gr.Row():
211
+ b_scene = gr.Textbox(label="สถานที่ / ฉาก", placeholder="เช่น คาเฟ่, ริมทะเล, ในสวน")
212
+ b_light = gr.Textbox(label="แสง", placeholder="เช่น แสงเช้านุ่มๆ, แสงสตูดิโอ")
213
+ b_shot = gr.Textbox(label="มุมกล้อง / ช็อต", placeholder="เช่น เต็มตัว, ครึ่งตัว, โคลสอัพ")
214
+ build_btn = gr.Button("✨ สร้าง prompt → ใส่ในช่องด้านบน", variant="secondary")
215
+
216
  # State: ordered list of model ids (matches gallery order) + current selection.
217
  ids_state = gr.State(model_ids(MODELS))
218
  selected_id = gr.State(MODELS[0]["id"] if MODELS else None)
 
284
  reload_registry,
285
  outputs=[model_gallery, ids_state, selected_id, reload_status],
286
  )
287
+ build_btn.click(
288
+ build_prompt,
289
+ inputs=[b_subject, b_age, b_ethnicity, b_body, b_hair, b_eyes, b_outfit,
290
+ b_pose, b_expr, b_scene, b_light, b_shot],
291
+ outputs=prompt,
292
+ )
293
 
294
  gen_inputs = [selected_id, mode_radio, prompt, negative_prompt, ref_image,
295
  steps, guidance, denoise, ip_scale, width, height, seed, randomize,