Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- apps/text_tools.py +62 -18
apps/text_tools.py
CHANGED
|
@@ -200,17 +200,18 @@ def calculate_llava_next_tokens(text, image_groups, tokenizer, max_pixels):
|
|
| 200 |
|
| 201 |
# --- Actual UI Logic ---
|
| 202 |
|
| 203 |
-
def run_calculation(text, model,
|
| 204 |
-
#
|
|
|
|
| 205 |
image_groups = []
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
| 212 |
try:
|
| 213 |
-
c, w, h = row
|
| 214 |
c = int(c)
|
| 215 |
w = int(w)
|
| 216 |
h = int(h)
|
|
@@ -281,16 +282,53 @@ def create_ui():
|
|
| 281 |
text_input = gr.Textbox(lines=5, label="输入文本 (Text)", placeholder="输入 Prompt...")
|
| 282 |
|
| 283 |
with gr.Accordion("🖼️ 图片设置 (Images)", open=True):
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
value=
|
| 288 |
-
label="
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
)
|
|
|
|
| 292 |
with gr.Row():
|
| 293 |
-
img_max_pixels = gr.Number(value=
|
| 294 |
|
| 295 |
with gr.Accordion("🎥 视频设置 (Videos)", open=False):
|
| 296 |
with gr.Row():
|
|
@@ -313,6 +351,12 @@ def create_ui():
|
|
| 313 |
|
| 314 |
btn.click(
|
| 315 |
run_calculation,
|
| 316 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
[out_json, out_file]
|
| 318 |
)
|
|
|
|
| 200 |
|
| 201 |
# --- Actual UI Logic ---
|
| 202 |
|
| 203 |
+
def run_calculation(text, model, img_max_pixels, vid_count, vid_frames, vid_w, vid_h, *args):
|
| 204 |
+
# Parse variable number of image group arguments
|
| 205 |
+
# args structure: c1, w1, h1, c2, w2, h2, ...
|
| 206 |
image_groups = []
|
| 207 |
+
|
| 208 |
+
# Group args into triplets
|
| 209 |
+
for i in range(0, len(args), 3):
|
| 210 |
+
if i + 2 < len(args):
|
| 211 |
+
c = args[i]
|
| 212 |
+
w = args[i+1]
|
| 213 |
+
h = args[i+2]
|
| 214 |
try:
|
|
|
|
| 215 |
c = int(c)
|
| 216 |
w = int(w)
|
| 217 |
h = int(h)
|
|
|
|
| 282 |
text_input = gr.Textbox(lines=5, label="输入文本 (Text)", placeholder="输入 Prompt...")
|
| 283 |
|
| 284 |
with gr.Accordion("🖼️ 图片设置 (Images)", open=True):
|
| 285 |
+
# Group 1 (Always visible)
|
| 286 |
+
with gr.Row():
|
| 287 |
+
img_c_1 = gr.Number(value=1, label="图片数量 (Group 1)", precision=0)
|
| 288 |
+
img_w_1 = gr.Number(value=1024, label="宽 (px)")
|
| 289 |
+
img_h_1 = gr.Number(value=1024, label="高 (px)")
|
| 290 |
+
|
| 291 |
+
# Group 2 (Hidden by default)
|
| 292 |
+
with gr.Row(visible=False) as group_2:
|
| 293 |
+
img_c_2 = gr.Number(value=1, label="图片数量 (Group 2)", precision=0)
|
| 294 |
+
img_w_2 = gr.Number(value=1024, label="宽 (px)")
|
| 295 |
+
img_h_2 = gr.Number(value=1024, label="高 (px)")
|
| 296 |
+
|
| 297 |
+
# Group 3 (Hidden by default)
|
| 298 |
+
with gr.Row(visible=False) as group_3:
|
| 299 |
+
img_c_3 = gr.Number(value=1, label="图片数量 (Group 3)", precision=0)
|
| 300 |
+
img_w_3 = gr.Number(value=1024, label="宽 (px)")
|
| 301 |
+
img_h_3 = gr.Number(value=1024, label="高 (px)")
|
| 302 |
+
|
| 303 |
+
# Group 4 (Hidden by default)
|
| 304 |
+
with gr.Row(visible=False) as group_4:
|
| 305 |
+
img_c_4 = gr.Number(value=1, label="图片数量 (Group 4)", precision=0)
|
| 306 |
+
img_w_4 = gr.Number(value=1024, label="宽 (px)")
|
| 307 |
+
img_h_4 = gr.Number(value=1024, label="高 (px)")
|
| 308 |
+
|
| 309 |
+
add_group_btn = gr.Button("➕ 增加一组图片 (Add Group)", size="sm")
|
| 310 |
+
|
| 311 |
+
# State to track visible groups
|
| 312 |
+
visible_groups = gr.State(1)
|
| 313 |
+
|
| 314 |
+
def add_group(curr_count):
|
| 315 |
+
next_count = curr_count + 1
|
| 316 |
+
# Return updates for group_2, group_3, group_4
|
| 317 |
+
return (
|
| 318 |
+
next_count,
|
| 319 |
+
gr.update(visible=next_count >= 2),
|
| 320 |
+
gr.update(visible=next_count >= 3),
|
| 321 |
+
gr.update(visible=next_count >= 4)
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
+
add_group_btn.click(
|
| 325 |
+
add_group,
|
| 326 |
+
[visible_groups],
|
| 327 |
+
[visible_groups, group_2, group_3, group_4]
|
| 328 |
)
|
| 329 |
+
|
| 330 |
with gr.Row():
|
| 331 |
+
img_max_pixels = gr.Number(value=1280*1280, label="Max Pixels (最大像素限制)", precision=0)
|
| 332 |
|
| 333 |
with gr.Accordion("🎥 视频设置 (Videos)", open=False):
|
| 334 |
with gr.Row():
|
|
|
|
| 351 |
|
| 352 |
btn.click(
|
| 353 |
run_calculation,
|
| 354 |
+
[
|
| 355 |
+
text_input, model_select, img_max_pixels, vid_count, vid_frames, vid_w, vid_h,
|
| 356 |
+
img_c_1, img_w_1, img_h_1,
|
| 357 |
+
img_c_2, img_w_2, img_h_2,
|
| 358 |
+
img_c_3, img_w_3, img_h_3,
|
| 359 |
+
img_c_4, img_w_4, img_h_4
|
| 360 |
+
],
|
| 361 |
[out_json, out_file]
|
| 362 |
)
|