MashiroLn commited on
Commit
df0e4e5
·
verified ·
1 Parent(s): a1f2cd8

Upload folder using huggingface_hub

Browse files
apps/paper_image_tool.py CHANGED
@@ -315,45 +315,6 @@ global_rules = {}
315
  # Store overrides: {sample_id: {type: rule}}
316
  global_overrides = {}
317
 
318
- def get_rules_summary():
319
- lines = []
320
-
321
- # Batch Rules
322
- if global_rules:
323
- lines.append("#### 📦 Batch Rules")
324
- for t, r in global_rules.items():
325
- p = r['params']
326
- p_str = ""
327
- if r['action'] == 'Resize':
328
- p_str = f"{p.get('w')}x{p.get('h')}"
329
- elif r['action'] == 'Auto Trim':
330
- p_str = f"Thresh={p.get('threshold')}"
331
- elif r['action'] == 'Manual Crop':
332
- p_str = f"x={p.get('x')},y={p.get('y')},w={p.get('w')},h={p.get('h')}"
333
-
334
- lines.append(f"* **{t}**: {r['action']} `[{p_str}]`")
335
-
336
- # Overrides
337
- if global_overrides:
338
- lines.append("\n#### 🔧 Overrides")
339
- for sid, types in global_overrides.items():
340
- for t, r in types.items():
341
- p = r['params']
342
- p_str = ""
343
- if r['action'] == 'Resize':
344
- p_str = f"{p.get('w')}x{p.get('h')}"
345
- elif r['action'] == 'Auto Trim':
346
- p_str = f"Thresh={p.get('threshold')}"
347
- elif r['action'] == 'Manual Crop':
348
- p_str = f"x={p.get('x')},y={p.get('y')},w={p.get('w')},h={p.get('h')}"
349
-
350
- lines.append(f"* **{sid}** ({t}): {r['action']} `[{p_str}]`")
351
-
352
- if not lines:
353
- return "No rules configured yet."
354
-
355
- return "\n".join(lines)
356
-
357
  def handle_upload(file, use_llm_chk):
358
  if file is None:
359
  return None, gr.update(choices=[])
@@ -368,11 +329,11 @@ def handle_upload(file, use_llm_chk):
368
 
369
  summary_text = f"Found {len(samples)} samples and {len(types)} types.\nTypes: {', '.join(types)}"
370
 
371
- return df, gr.update(choices=samples, value=samples[0] if samples else None), gr.update(choices=types, value=types[0] if types else None), summary_text, get_rules_summary()
372
 
373
  def save_rule(type_sel, action, p1, p2, p3, p4):
374
  if not type_sel:
375
- return "No type selected.", get_rules_summary()
376
 
377
  params = {}
378
  if action == 'Manual Crop':
@@ -384,11 +345,11 @@ def save_rule(type_sel, action, p1, p2, p3, p4):
384
 
385
  rule = {'action': action, 'params': params}
386
  global_rules[type_sel] = rule
387
- return f"Saved rule for Type: {type_sel} -> {action}", get_rules_summary()
388
 
389
  def save_override(sample_id, type_sel, action, p1, p2, p3, p4):
390
  if not sample_id or not type_sel:
391
- return "Sample or Type not selected.", get_rules_summary()
392
 
393
  params = {}
394
  if action == 'Manual Crop':
@@ -404,13 +365,13 @@ def save_override(sample_id, type_sel, action, p1, p2, p3, p4):
404
  global_overrides[sample_id] = {}
405
  global_overrides[sample_id][type_sel] = rule
406
 
407
- return f"Saved OVERRIDE for {sample_id} / {type_sel} -> {action}", get_rules_summary()
408
 
409
  def clear_override(sample_id, type_sel):
410
  if sample_id in global_overrides and type_sel in global_overrides[sample_id]:
411
  del global_overrides[sample_id][type_sel]
412
- return f"Cleared override for {sample_id} / {type_sel}", get_rules_summary()
413
- return "No override found to clear.", get_rules_summary()
414
 
415
  def update_preview(sample_id, type_sel, action, p1, p2, p3, p4):
416
  # p1-p4 are generic params mapped based on action
@@ -472,7 +433,11 @@ def create_paper_tool():
472
  # So we don't need to create a new gr.Blocks() here unless we want a nested one.
473
  # To keep it clean and consistent with other tools, we'll just define the layout.
474
  if True: # Placeholder to keep indentation
475
- gr.Markdown("Upload a zip of your images. The tool will try to organize them by Type and Sample ID.")
 
 
 
 
476
 
477
  with gr.Row():
478
  with gr.Column(scale=1):
@@ -514,12 +479,11 @@ def create_paper_tool():
514
  preview_gallery = gr.Gallery(label="Preview", columns=2)
515
 
516
  gr.Markdown("### 🚀 Batch Process")
517
- rules_summary_display = gr.Markdown("No rules configured yet.")
518
  process_btn = gr.Button("Apply Rules & Download", variant="primary")
519
  download_output = gr.File(label="Download Result")
520
 
521
  # Event Wiring
522
- analyze_btn.click(handle_upload, inputs=[zip_input, use_llm_chk], outputs=[file_table, sample_selector, type_selector, structure_info, rules_summary_display])
523
 
524
  preview_btn.click(update_preview,
525
  inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],
@@ -527,15 +491,15 @@ def create_paper_tool():
527
 
528
  save_rule_btn.click(save_rule,
529
  inputs=[type_selector, action_selector, p1, p2, p3, p4],
530
- outputs=[rule_status, rules_summary_display])
531
 
532
  save_override_btn.click(save_override,
533
  inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],
534
- outputs=[rule_status, rules_summary_display])
535
 
536
  clear_override_btn.click(clear_override,
537
  inputs=[sample_selector, type_selector],
538
- outputs=[rule_status, rules_summary_display])
539
 
540
  process_btn.click(run_batch_process, inputs=[], outputs=[download_output])
541
  with gr.Accordion("💻 Code Gen Helper (Fallback)", open=False):
 
315
  # Store overrides: {sample_id: {type: rule}}
316
  global_overrides = {}
317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  def handle_upload(file, use_llm_chk):
319
  if file is None:
320
  return None, gr.update(choices=[])
 
329
 
330
  summary_text = f"Found {len(samples)} samples and {len(types)} types.\nTypes: {', '.join(types)}"
331
 
332
+ return df, gr.update(choices=samples, value=samples[0] if samples else None), gr.update(choices=types, value=types[0] if types else None), summary_text
333
 
334
  def save_rule(type_sel, action, p1, p2, p3, p4):
335
  if not type_sel:
336
+ return "No type selected."
337
 
338
  params = {}
339
  if action == 'Manual Crop':
 
345
 
346
  rule = {'action': action, 'params': params}
347
  global_rules[type_sel] = rule
348
+ return f"Saved rule for Type: {type_sel} -> {action}"
349
 
350
  def save_override(sample_id, type_sel, action, p1, p2, p3, p4):
351
  if not sample_id or not type_sel:
352
+ return "Sample or Type not selected."
353
 
354
  params = {}
355
  if action == 'Manual Crop':
 
365
  global_overrides[sample_id] = {}
366
  global_overrides[sample_id][type_sel] = rule
367
 
368
+ return f"Saved OVERRIDE for {sample_id} / {type_sel} -> {action}"
369
 
370
  def clear_override(sample_id, type_sel):
371
  if sample_id in global_overrides and type_sel in global_overrides[sample_id]:
372
  del global_overrides[sample_id][type_sel]
373
+ return f"Cleared override for {sample_id} / {type_sel}"
374
+ return "No override found to clear."
375
 
376
  def update_preview(sample_id, type_sel, action, p1, p2, p3, p4):
377
  # p1-p4 are generic params mapped based on action
 
433
  # So we don't need to create a new gr.Blocks() here unless we want a nested one.
434
  # To keep it clean and consistent with other tools, we'll just define the layout.
435
  if True: # Placeholder to keep indentation
436
+ gr.Markdown("""
437
+ ## 📑 Image Auto Cropper (自动裁图)
438
+ **English:** Organize, crop, and batch process research images. Supports structure inference via LLM and specific overrides.
439
+ **中文:** 整理、裁剪和批量处理可视化图片。支持通过 LLM 推断目录结构以及针对特定样本的例外处理。
440
+ """)
441
 
442
  with gr.Row():
443
  with gr.Column(scale=1):
 
479
  preview_gallery = gr.Gallery(label="Preview", columns=2)
480
 
481
  gr.Markdown("### 🚀 Batch Process")
 
482
  process_btn = gr.Button("Apply Rules & Download", variant="primary")
483
  download_output = gr.File(label="Download Result")
484
 
485
  # Event Wiring
486
+ analyze_btn.click(handle_upload, inputs=[zip_input, use_llm_chk], outputs=[file_table, sample_selector, type_selector, structure_info])
487
 
488
  preview_btn.click(update_preview,
489
  inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],
 
491
 
492
  save_rule_btn.click(save_rule,
493
  inputs=[type_selector, action_selector, p1, p2, p3, p4],
494
+ outputs=[rule_status])
495
 
496
  save_override_btn.click(save_override,
497
  inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],
498
+ outputs=[rule_status])
499
 
500
  clear_override_btn.click(clear_override,
501
  inputs=[sample_selector, type_selector],
502
+ outputs=[rule_status])
503
 
504
  process_btn.click(run_batch_process, inputs=[], outputs=[download_output])
505
  with gr.Accordion("💻 Code Gen Helper (Fallback)", open=False):
apps/pdf_cropper.py CHANGED
@@ -59,6 +59,11 @@ def create_ui():
59
  注意:不要在这里创建 gr.Blocks(),直接写 Row/Column 即可,
60
  因为它们会被嵌入到主程序的 Tab 中。
61
  """
 
 
 
 
 
62
  with gr.Row():
63
  with gr.Column():
64
  file_input = gr.File(file_count="multiple", file_types=["image"], label="上传图片 (支持多选)")
 
59
  注意:不要在这里创建 gr.Blocks(),直接写 Row/Column 即可,
60
  因为它们会被嵌入到主程序的 Tab 中。
61
  """
62
+ gr.Markdown("""
63
+ ## 📄 Img2PDF (Image转PDF)
64
+ **English:** Convert images to PDF with smart whitespace trimming.
65
+ **中文:** 将图片转换为 PDF,并支持自动裁剪白边。
66
+ """)
67
  with gr.Row():
68
  with gr.Column():
69
  file_input = gr.File(file_count="multiple", file_types=["image"], label="上传图片 (支持多选)")
apps/text_tools.py CHANGED
@@ -272,6 +272,11 @@ def run_calculation(text, model, img_max_pixels, vid_count, vid_frames, vid_w, v
272
  return result, token_file_path
273
 
274
  def create_ui():
 
 
 
 
 
275
  with gr.Row():
276
  with gr.Column(scale=1):
277
  model_select = gr.Dropdown(
 
272
  return result, token_file_path
273
 
274
  def create_ui():
275
+ gr.Markdown("""
276
+ ## 📝 Token Stats (文本/多模态 Token 统计)
277
+ Estimate token usage for text, images, and videos using various model tokenizers (e.g., Qwen2.5-VL, LLaVa).
278
+ 估算文本、图片和视频在不同模型(如 Qwen2.5-VL, LLaVa)下的 Token 用量。
279
+ """)
280
  with gr.Row():
281
  with gr.Column(scale=1):
282
  model_select = gr.Dropdown(