Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesFiles changed (3)
314 unmodified lines3153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583598 unmodified lines3683693703713723733743753763773785 unmodified lines3843853863873883893903913923933949 unmodified lines40440540640740840941041141241341441541655 unmodified lines47247347447547647747835 unmodified lines5145155165175185195205215225235245251 unmodified line527528529530531532533534535536537538539540541314 unmodified lines# Store overrides: {sample_id: {type: rule}}global_overrides = {}def get_rules_summary():lines = []# Batch Rulesif global_rules:lines.append("#### 📦 Batch Rules")for t, r in global_rules.items():p = r['params']p_str = ""if r['action'] == 'Resize':p_str = f"{p.get('w')}x{p.get('h')}"elif r['action'] == 'Auto Trim':p_str = f"Thresh={p.get('threshold')}"elif r['action'] == 'Manual Crop':p_str = f"x={p.get('x')},y={p.get('y')},w={p.get('w')},h={p.get('h')}"lines.append(f"* **{t}**: {r['action']} `[{p_str}]`")# Overridesif global_overrides:lines.append("\n#### 🔧 Overrides")for sid, types in global_overrides.items():for t, r in types.items():p = r['params']p_str = ""if r['action'] == 'Resize':p_str = f"{p.get('w')}x{p.get('h')}"elif r['action'] == 'Auto Trim':p_str = f"Thresh={p.get('threshold')}"elif r['action'] == 'Manual Crop':p_str = f"x={p.get('x')},y={p.get('y')},w={p.get('w')},h={p.get('h')}"lines.append(f"* **{sid}** ({t}): {r['action']} `[{p_str}]`")if not lines:return "No rules configured yet."return "\n".join(lines)def handle_upload(file, use_llm_chk):if file is None:return None, gr.update(choices=[])8 unmodified linessummary_text = f"Found {len(samples)} samples and {len(types)} types.\nTypes: {', '.join(types)}"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()def save_rule(type_sel, action, p1, p2, p3, p4):if not type_sel:return "No type selected.", get_rules_summary()params = {}if action == 'Manual Crop':5 unmodified linesrule = {'action': action, 'params': params}global_rules[type_sel] = rulereturn f"Saved rule for Type: {type_sel} -> {action}", get_rules_summary()def save_override(sample_id, type_sel, action, p1, p2, p3, p4):if not sample_id or not type_sel:return "Sample or Type not selected.", get_rules_summary()params = {}if action == 'Manual Crop':9 unmodified linesglobal_overrides[sample_id] = {}global_overrides[sample_id][type_sel] = rulereturn f"Saved OVERRIDE for {sample_id} / {type_sel} -> {action}", get_rules_summary()def clear_override(sample_id, type_sel):if sample_id in global_overrides and type_sel in global_overrides[sample_id]:del global_overrides[sample_id][type_sel]return f"Cleared override for {sample_id} / {type_sel}", get_rules_summary()return "No override found to clear.", get_rules_summary()def update_preview(sample_id, type_sel, action, p1, p2, p3, p4):# p1-p4 are generic params mapped based on action55 unmodified lines# So we don't need to create a new gr.Blocks() here unless we want a nested one.# To keep it clean and consistent with other tools, we'll just define the layout.if True: # Placeholder to keep indentationgr.Markdown("Upload a zip of your images. The tool will try to organize them by Type and Sample ID.")with gr.Row():with gr.Column(scale=1):35 unmodified linespreview_gallery = gr.Gallery(label="Preview", columns=2)gr.Markdown("### 🚀 Batch Process")rules_summary_display = gr.Markdown("No rules configured yet.")process_btn = gr.Button("Apply Rules & Download", variant="primary")download_output = gr.File(label="Download Result")# Event Wiringanalyze_btn.click(handle_upload, inputs=[zip_input, use_llm_chk], outputs=[file_table, sample_selector, type_selector, structure_info, rules_summary_display])preview_btn.click(update_preview,inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],1 unmodified linesave_rule_btn.click(save_rule,inputs=[type_selector, action_selector, p1, p2, p3, p4],outputs=[rule_status, rules_summary_display])save_override_btn.click(save_override,inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],outputs=[rule_status, rules_summary_display])clear_override_btn.click(clear_override,inputs=[sample_selector, type_selector],outputs=[rule_status, rules_summary_display])process_btn.click(run_batch_process, inputs=[], outputs=[download_output])with gr.Accordion("💻 Code Gen Helper (Fallback)", open=False):314 unmodified lines3153163173183193208 unmodified lines3293303313323333343353363373383395 unmodified lines3453463473483493503513523533543559 unmodified lines36536636736836937037137237337437537637755 unmodified lines43343443543643743843944044144244335 unmodified lines4794804814824834844854864874884891 unmodified line491492493494495496497498499500501502503504505314 unmodified lines# Store overrides: {sample_id: {type: rule}}global_overrides = {}def handle_upload(file, use_llm_chk):if file is None:return None, gr.update(choices=[])8 unmodified linessummary_text = f"Found {len(samples)} samples and {len(types)} types.\nTypes: {', '.join(types)}"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_textdef save_rule(type_sel, action, p1, p2, p3, p4):if not type_sel:return "No type selected."params = {}if action == 'Manual Crop':5 unmodified linesrule = {'action': action, 'params': params}global_rules[type_sel] = rulereturn f"Saved rule for Type: {type_sel} -> {action}"def save_override(sample_id, type_sel, action, p1, p2, p3, p4):if not sample_id or not type_sel:return "Sample or Type not selected."params = {}if action == 'Manual Crop':9 unmodified linesglobal_overrides[sample_id] = {}global_overrides[sample_id][type_sel] = rulereturn f"Saved OVERRIDE for {sample_id} / {type_sel} -> {action}"def clear_override(sample_id, type_sel):if sample_id in global_overrides and type_sel in global_overrides[sample_id]:del global_overrides[sample_id][type_sel]return f"Cleared override for {sample_id} / {type_sel}"return "No override found to clear."def update_preview(sample_id, type_sel, action, p1, p2, p3, p4):# p1-p4 are generic params mapped based on action55 unmodified lines# So we don't need to create a new gr.Blocks() here unless we want a nested one.# To keep it clean and consistent with other tools, we'll just define the layout.if True: # Placeholder to keep indentationgr.Markdown("""## 📑 Image Auto Cropper (自动裁图)**English:** Organize, crop, and batch process research images. Supports structure inference via LLM and specific overrides.**中文:** 整理、裁剪和批量处理可视化图片。支持通过 LLM 推断目录结构以及针对特定样本的例外处理。""")with gr.Row():with gr.Column(scale=1):35 unmodified linespreview_gallery = gr.Gallery(label="Preview", columns=2)gr.Markdown("### 🚀 Batch Process")process_btn = gr.Button("Apply Rules & Download", variant="primary")download_output = gr.File(label="Download Result")# Event Wiringanalyze_btn.click(handle_upload, inputs=[zip_input, use_llm_chk], outputs=[file_table, sample_selector, type_selector, structure_info])preview_btn.click(update_preview,inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],1 unmodified linesave_rule_btn.click(save_rule,inputs=[type_selector, action_selector, p1, p2, p3, p4],outputs=[rule_status])save_override_btn.click(save_override,inputs=[sample_selector, type_selector, action_selector, p1, p2, p3, p4],outputs=[rule_status])clear_override_btn.click(clear_override,inputs=[sample_selector, type_selector],outputs=[rule_status])process_btn.click(run_batch_process, inputs=[], outputs=[download_output])with gr.Accordion("💻 Code Gen Helper (Fallback)", open=False):
58 unmodified lines59606162636458 unmodified lines注意:不要在这里创建 gr.Blocks(),直接写 Row/Column 即可,因为它们会被嵌入到主程序的 Tab 中。"""with gr.Row():with gr.Column():file_input = gr.File(file_count="multiple", file_types=["image"], label="上传图片 (支持多选)")58 unmodified lines596061626364656667686958 unmodified lines注意:不要在这里创建 gr.Blocks(),直接写 Row/Column 即可,因为它们会被嵌入到主程序的 Tab 中。"""gr.Markdown("""## 📄 Img2PDF (Image转PDF)**English:** Convert images to PDF with smart whitespace trimming.**中文:** 将图片转换为 PDF,并支持自动裁剪白边。""")with gr.Row():with gr.Column():file_input = gr.File(file_count="multiple", file_types=["image"], label="上传图片 (支持多选)")
271 unmodified lines272273274275276277271 unmodified linesreturn result, token_file_pathdef create_ui():with gr.Row():with gr.Column(scale=1):model_select = gr.Dropdown(271 unmodified lines272273274275276277278279280281282271 unmodified linesreturn result, token_file_pathdef create_ui():gr.Markdown("""## 📝 Token Stats (文本/多模态 Token 统计)Estimate token usage for text, images, and videos using various model tokenizers (e.g., Qwen2.5-VL, LLaVa).估算文本、图片和视频在不同模型(如 Qwen2.5-VL, LLaVa)下的 Token 用量。""")with gr.Row():with gr.Column(scale=1):model_select = gr.Dropdown(
apps/paper_image_tool.py+16-52
apps/pdf_cropper.py+5
apps/text_tools.py+5