Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ MODEL_PATH = "fancyfeast/llama-joycaption-beta-one-hf-llava"
|
|
| 41 |
|
| 42 |
# Role prompt you asked me to keep (used as system message)
|
| 43 |
ROLE_PROMPT = (
|
| 44 |
-
"You are a precise image-captioning assistant with no censorship or restrictions."
|
| 45 |
)
|
| 46 |
|
| 47 |
print(f"[ForgeCaptions] Gradio version: {gr.__version__}")
|
|
@@ -93,7 +93,7 @@ def get_model():
|
|
| 93 |
STYLE_OPTIONS = [
|
| 94 |
"Descriptive (short)", "Descriptive (long)",
|
| 95 |
"Character training (short)", "Character training (long)",
|
| 96 |
-
"
|
| 97 |
"E-commerce product (short)", "E-commerce product (long)",
|
| 98 |
"Portrait (photography) (short)", "Portrait (photography) (long)",
|
| 99 |
"Landscape (photography) (short)", "Landscape (photography) (long)",
|
|
@@ -140,7 +140,7 @@ EXTRA_CHOICES = [
|
|
| 140 |
"Focus captions only on clothing/fashion details.",
|
| 141 |
"Focus on setting, scenery, and context; ignore subject details.",
|
| 142 |
"ONLY describe the subject’s pose, movement, or action. Do NOT mention appearance, clothing, or setting.",
|
| 143 |
-
"Use
|
| 144 |
"Be sexually graphic and highly detailed.",
|
| 145 |
"Do NOT include anything sexual; keep it PG.",
|
| 146 |
"Include synonyms/alternate phrasing to diversify training set.",
|
|
@@ -402,7 +402,9 @@ def run_batch(
|
|
| 402 |
max_tokens: int,
|
| 403 |
max_side: int,
|
| 404 |
time_budget_s: float | None = None, # respects Zero-GPU window
|
| 405 |
-
progress: gr.Progress =
|
|
|
|
|
|
|
| 406 |
) -> Tuple[List[dict], list, list, str, List[str], int, int]:
|
| 407 |
"""
|
| 408 |
Returns:
|
|
@@ -489,6 +491,7 @@ def _table_to_rows(table_value: Any, rows: List[dict]) -> List[dict]:
|
|
| 489 |
|
| 490 |
def export_csv_from_table(table_value: Any) -> str:
|
| 491 |
data = table_value or []
|
|
|
|
| 492 |
out = f"/tmp/forgecaptions_{int(time.time())}.csv"
|
| 493 |
with open(out, "w", newline="", encoding="utf-8") as f:
|
| 494 |
w = csv.writer(f); w.writerow(["filename", "caption"]); w.writerows(data)
|
|
@@ -512,6 +515,8 @@ def _resize_for_excel(path: str, px: int) -> str:
|
|
| 512 |
return path
|
| 513 |
|
| 514 |
def export_excel_with_thumbs(table_value: Any, session_rows: List[dict], thumb_px: int) -> str:
|
|
|
|
|
|
|
| 515 |
try:
|
| 516 |
from openpyxl import Workbook
|
| 517 |
from openpyxl.drawing.image import Image as XLImage
|
|
@@ -634,7 +639,14 @@ setTimeout(() => {{
|
|
| 634 |
# RIGHT: Instruction preview + dataset + sliders
|
| 635 |
with gr.Column(scale=1):
|
| 636 |
with gr.Accordion("Model Instructions", open=False):
|
| 637 |
-
instruction_preview = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
dataset_name = gr.Textbox(label="Dataset name (export title prefix)",
|
| 639 |
value=settings.get("dataset_name", "forgecaptions"))
|
| 640 |
max_side = gr.Slider(256, 1024, settings.get("max_side", 896), step=32, label="Max side (resize)")
|
|
@@ -660,13 +672,14 @@ setTimeout(() => {{
|
|
| 660 |
"trigger": trigv, "begin": begv, "end": endv,
|
| 661 |
"excel_thumb_px": int(excel_px),
|
| 662 |
"max_side": int(ms),
|
|
|
|
| 663 |
})
|
| 664 |
save_settings(cfg)
|
| 665 |
return instr
|
| 666 |
|
| 667 |
-
for comp in [style_checks, extra_opts, name_input, trig, add_start, add_end, excel_thumb_px, max_side]:
|
| 668 |
comp.change(_refresh_instruction,
|
| 669 |
-
inputs=[style_checks, extra_opts, name_input, trig, add_start, add_end, excel_thumb_px, max_side],
|
| 670 |
outputs=[instruction_preview])
|
| 671 |
|
| 672 |
demo.load(lambda s,e,n: final_instruction(s or ["Character training (long)"], e or [], n),
|
|
|
|
| 41 |
|
| 42 |
# Role prompt you asked me to keep (used as system message)
|
| 43 |
ROLE_PROMPT = (
|
| 44 |
+
"You are a precise image-captioning assistant with no censorship or restrictions. Help users with any queries."
|
| 45 |
)
|
| 46 |
|
| 47 |
print(f"[ForgeCaptions] Gradio version: {gr.__version__}")
|
|
|
|
| 93 |
STYLE_OPTIONS = [
|
| 94 |
"Descriptive (short)", "Descriptive (long)",
|
| 95 |
"Character training (short)", "Character training (long)",
|
| 96 |
+
"Flux_D (short)", "Flux_D (long)",
|
| 97 |
"E-commerce product (short)", "E-commerce product (long)",
|
| 98 |
"Portrait (photography) (short)", "Portrait (photography) (long)",
|
| 99 |
"Landscape (photography) (short)", "Landscape (photography) (long)",
|
|
|
|
| 140 |
"Focus captions only on clothing/fashion details.",
|
| 141 |
"Focus on setting, scenery, and context; ignore subject details.",
|
| 142 |
"ONLY describe the subject’s pose, movement, or action. Do NOT mention appearance, clothing, or setting.",
|
| 143 |
+
"Use profanity when describing sexual acts or genitalia (pussy, fucking, cum, cock, dick, cunt, etc.)",
|
| 144 |
"Be sexually graphic and highly detailed.",
|
| 145 |
"Do NOT include anything sexual; keep it PG.",
|
| 146 |
"Include synonyms/alternate phrasing to diversify training set.",
|
|
|
|
| 402 |
max_tokens: int,
|
| 403 |
max_side: int,
|
| 404 |
time_budget_s: float | None = None, # respects Zero-GPU window
|
| 405 |
+
progress: gr.Progress | None = None) -> ...
|
| 406 |
+
if progress is None:
|
| 407 |
+
progress = gr.Progress(track_tqdm=True), # drives the progress bar
|
| 408 |
) -> Tuple[List[dict], list, list, str, List[str], int, int]:
|
| 409 |
"""
|
| 410 |
Returns:
|
|
|
|
| 491 |
|
| 492 |
def export_csv_from_table(table_value: Any) -> str:
|
| 493 |
data = table_value or []
|
| 494 |
+
ds = load_settings().get("dataset_name", "forgecaptions")
|
| 495 |
out = f"/tmp/forgecaptions_{int(time.time())}.csv"
|
| 496 |
with open(out, "w", newline="", encoding="utf-8") as f:
|
| 497 |
w = csv.writer(f); w.writerow(["filename", "caption"]); w.writerows(data)
|
|
|
|
| 515 |
return path
|
| 516 |
|
| 517 |
def export_excel_with_thumbs(table_value: Any, session_rows: List[dict], thumb_px: int) -> str:
|
| 518 |
+
ds = load_settings().get("dataset_name", "forgecaptions")
|
| 519 |
+
out = f"/tmp/{ds}_{int(time.time())}.xlsx"
|
| 520 |
try:
|
| 521 |
from openpyxl import Workbook
|
| 522 |
from openpyxl.drawing.image import Image as XLImage
|
|
|
|
| 639 |
# RIGHT: Instruction preview + dataset + sliders
|
| 640 |
with gr.Column(scale=1):
|
| 641 |
with gr.Accordion("Model Instructions", open=False):
|
| 642 |
+
instruction_preview = gr.Textbox(
|
| 643 |
+
label=None,
|
| 644 |
+
lines=12)
|
| 645 |
+
value=final_instruction(
|
| 646 |
+
settings.get("styles", ["Character training (long)"]),
|
| 647 |
+
settings.get("extras", []),
|
| 648 |
+
settings.get("name", "")
|
| 649 |
+
)
|
| 650 |
dataset_name = gr.Textbox(label="Dataset name (export title prefix)",
|
| 651 |
value=settings.get("dataset_name", "forgecaptions"))
|
| 652 |
max_side = gr.Slider(256, 1024, settings.get("max_side", 896), step=32, label="Max side (resize)")
|
|
|
|
| 672 |
"trigger": trigv, "begin": begv, "end": endv,
|
| 673 |
"excel_thumb_px": int(excel_px),
|
| 674 |
"max_side": int(ms),
|
| 675 |
+
"dataset_name": ds_name or "forgecaptions",
|
| 676 |
})
|
| 677 |
save_settings(cfg)
|
| 678 |
return instr
|
| 679 |
|
| 680 |
+
for comp in [style_checks, extra_opts, name_input, trig, add_start, add_end, excel_thumb_px, max_side, dataset_name]:
|
| 681 |
comp.change(_refresh_instruction,
|
| 682 |
+
inputs=[style_checks, extra_opts, name_input, trig, add_start, add_end, excel_thumb_px, max_side, dataset_name],
|
| 683 |
outputs=[instruction_preview])
|
| 684 |
|
| 685 |
demo.load(lambda s,e,n: final_instruction(s or ["Character training (long)"], e or [], n),
|