Edit-Banana README

项目的 README,来自 github.com/BIT-DataLab/Edit-Banana。合并为一个 markdown 文件:README.md。

Edit Banana Logo

🍌 Edit Banana

中文 | English

Universal Content Re-Editor: Make the Uneditable, Editable

Break free from static formats. Our platform empowers you to transform fixed content into fully manipulatable assets. Powered by SAM 3 and multimodal large models, it enables high-fidelity reconstruction that preserves the original diagram details and logical relationships.

Python License CUDA WeChat GitHub stars AtomGit Star


Try It Now!

Try Online Demo

👆 Click above or https://www.editbanana.net/ or https://www.editfigure.com to try Edit Banana online! Upload an image to get editable DrawIO (XML) in seconds.

[!WARNING] Please note: Our GitHub repository currently trails behind our web-based service. For the most up-to-date features and performance, we recommend using our web platform.


💬 Join WeChat Group

Welcome to join our WeChat group to discuss and exchange ideas! Scan the QR code below to join:

WeChat Group QR Code
Scan to join the Edit Banana community

[!TIP] If the QR code has expired, please submit an Issue to request an updated one.

👨‍🏫 Leader

Guoren Wang

Professor · Doctoral Supervisor

Database Systems Uncertain Data Management Multimedia Data Management Distributed Query Processing

Homepage →

Ye Yuan

Professor · Doctoral Supervisor

Big Data Management Graph Data Management Spatio-temporal Data Distributed Computing

Homepage →

Chengliang Chai

Associate Professor · Doctoral Supervisor

Data-centric AI Large Language Models Data Lakes Database Systems

Homepage →

📮 Contact Us

For academic cooperation, technical docking, commercial licensing, project customization and other business inquiries, please contact us via email:

E-mail: [email protected]


📑 Table of Contents


📸 Effect Demonstration

High-Definition Input-Output Comparison (4 Typical Scenarios)

To demonstrate the high-fidelity conversion effect, we provides one-to-one comparisons between 4 scenarios of "original static formats" and "editable reconstruction results". All elements can be individually dragged, styled, and modified.

Scenario 1: Figures to DrawIO

🔒 Original Static Diagram (Input · Non-editable) 🔓 DrawIO Reconstruction Result (Output · Fully Editable)

Example 1: Basic Flowchart

Original Diagram 1

✨ Editable Flowchart

Reconstruction Result 1

Example 2: Multi-level Architecture

Original Diagram 2

✨ Editable Architecture

Reconstruction Result 2

Example 3: Technical Schematic

Original Diagram 3

✨ Editable Schematic

Reconstruction Result 3

Example 4: Scientific Formula

Original Diagram 4

✨ Editable Formula

Reconstruction Result 4

Scenario 2: Human in the Loop Modification



✨ Manual repair




✨ Save locally

[!NOTE] ✨ Conversion Highlights:

  1. Preserves the layout logic, color matching, and element hierarchy of the original diagram.
  2. 1:1 restoration of shape stroke/fill and arrow styles (dashed lines/thickness).
  3. Accurate text recognition, supporting direct subsequent editing and format adjustment.
  4. All elements are independently selectable, supporting native DrawIO template replacement and layout optimization.

🚀 Key Features


🛠️ Architecture Pipeline

  1. Input: Image (PNG/JPG/BMP/TIFF/WebP).
  2. Segmentation (SAM3): Using our fine-tuned SAM3 mask decoder.
  3. Text Extraction (Parallel):
    • Local OCR (Tesseract) detects text bounding boxes.
    • High-res crops of text/formula regions are sent to Pix2Text for LaTeX conversion.
  4. DrawIO XML Generation: Merging spatial data from SAM3 and text OCR results.

📂 Project Structure

Click to expand project structure
Edit-Banana/
├── config/               # Configuration files (copy config.yaml.example → config.yaml)
├── flowchart_text/       # OCR & Text Extraction Module (standalone entry)
│   ├── src/
│   └── main.py             # OCR-only entry point
├── input/                # [Manual] Input images directory
├── models/               # [Manual] Model weights (SAM3) and optional BPE vocab
├── output/               # [Manual] Results directory
├── sam3/                 # SAM3 library (see Installation: install from facebookresearch/sam3)
├── sam3_service/         # SAM3 HTTP service (optional, for multi-process deployment)
├── scripts/              # Setup and utility scripts
│   ├── setup_sam3.sh       # Install SAM3 lib and copy BPE to models/
│   ├── setup_rmbg.py       # Download RMBG model from ModelScope
│   └── merge_xml.py        # XML merge utilities
├── main.py               # CLI entry (modular pipeline)
├── server_pa.py          # FastAPI backend server
└── requirements.txt      # Python dependencies

📦 Installation & Setup

Follow these core phases to set up the project locally.

Phase 1: Environment & Base Setup

Configure your base environment and directory structure.

1. Prerequisites & Environment

2. Clone Repository & Init Directories

git clone https://github.com/BIT-DataLab/Edit-Banana.git
cd Edit-Banana
mkdir -p input output sam3_output

Phase 2: Models & Core Dependencies

Next, install the required packages and download necessary model weights (which should be placed in models/ and not committed).

1. Base Dependencies

pip install -r requirements.txt

2. SAM3 & Model Assets

🧩 Optional Capabilities (OCR Engine, Formula, RMBG) - Click to expand
  • PaddleOCR (Alternative/Better for mixed text): Use paddlepaddle==3.2.2 (avoiding 3.3.0 bug).

    pip install paddlepaddle==3.2.2 paddleocr.
    
  • Formula (Pix2Text):

    pip install pix2text onnxruntime-gpu.
    
  • Background Removal (RMBG): pip install onnxruntime modelscope then run python scripts/setup_rmbg.py.

Phase 3: Configuration & Troubleshooting

1. Final Configuration

Copy the example config and adjust the asset paths:

cp config/config.yaml.example config/config.yaml

Edit config.yaml to ensure sam3.checkpoint_path and sam3.bpe_path match your models/ locations.

🛠️ Before First Run Checklist & Troubleshooting - Click to expand

Checklist:

  • Config files copied and model paths set in config.yaml
  • SAM3 weights (sam3.pt) and BPE vocab placed under models/
  • Extracted SAM3 library via scripts/setup_sam3.sh Tesseract or PaddleOCR installed

Common Issues:

  • "no kernel image is available...": GPU arch mismatch. Upgrade PyTorch or set sam3.device: "cpu".
  • "Model file not found at ...rmbg/...": RMBG is optional. Enable by downloading via script.
  • "PaddleOCR inference failed...": Use paddlepaddle==3.2.2 or fallback to Tesseract.

🔤 Usage

Command Line Interface (CLI)

Supports image files (PNG, JPG, BMP, TIFF, WebP). To process a single image:

python main.py -i input/test_diagram.png

The output XML will be saved in the output/ directory. For batch processing, put images in input/ and run python main.py without -i.

Run and test locally

  1. One-time setup

    git clone https://github.com/BIT-DataLab/Edit-Banana.git && cd Edit-Banana
    python3 -m venv .venv && source .venv/bin/activate   # Linux/macOS; Windows: .venv\Scripts\activate
    pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118   # or CPU build
    pip install -r requirements.txt
    sudo apt install tesseract-ocr tesseract-ocr-chi-sim   # OCR (or equivalent on your OS)
    

    Install the SAM3 library and download model weights + BPE. Then:

    mkdir -p input output
    cp config/config.yaml.example config/config.yaml
    # Edit config/config.yaml: set sam3.checkpoint_path and sam3.bpe_path to your models/ paths
    
  2. Test with CLI

    # Put a diagram image in input/, e.g. input/test.png
    python main.py -i input/test.png
    # Output appears under output/<image_stem>/ (DrawIO XML and intermediates)
    
  3. Optional: test the web API

    python server_pa.py
    # In another terminal:
    curl -X POST http://localhost:8000/convert -F "file=@input/test.png"
    # Or open http://localhost:8000/docs and use the /convert endpoint with a file upload
    

⚙️ Configuration

Customize the pipeline behavior in config/config.yaml:


📌 Development Roadmap

Feature Module Status Description
Core Conversion Pipeline ✅ Completed Full pipeline of segmentation, reconstruction and OCR
Intelligent Arrow Connection ⚠️ In Development Automatically associate arrows with target shapes
DrawIO Template Adaptation 📍 Planned Support custom template import
Batch Export Optimization 📍 Planned Batch export to DrawIO files (.drawio)
Local LLM Adaptation 📍 Planned Support local VLM deployment, independent of APIs

🤝 Contribution Guidelines

Contributions of all kinds are welcome (code submissions, bug reports, feature suggestions):

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/xxx)
  3. Commit your changes (git commit -m 'feat: add xxx')
  4. Push to the branch (git push origin feature/xxx)
  5. Open a Pull Request

Bug Reports: Issues Feature Suggestions: Discussions


🤩 Contributors

Thanks to all developers who have contributed to the project and promoted its iteration!

Chai Chengliang, Zhang Chi, Lin Zheng, Rao Sijing, Yi Xiangjian, Zhou Nan, Yuan Weishuo, Wang Kejin, Li Jianhui, Zhang Junkai, Han Junyi, You Zirui, Xu Haochen, Yu Xinjiang


📄 License

This project is open-source under the Apache License 2.0, allowing commercial use and secondary development (with copyright notice retained).


🌟 Star History

🌟 If this project helps you, please star it to show your support!

Star History Chart

Edit-Banana (BIT-DataLab/Edit-Banana)

正在搜索数据库…

这是做什么的?它可以把静态图表的图片——流程图、多层级架构图、技术示意图、科学公式——转换成完全可编辑的 DrawIO 文件,底层由微调过的 SAM 3 分割模型和多模态大语言模型驱动。
这是在线网页服务,还是我自己在本地运行的工具?两者都有。托管的网页平台是推荐的、更新更及时的选择;这个仓库则是本地版,提供命令行工具和一个 Web API。你输入 PNG/JPG/BMP/TIFF/WebP 图片,就能得到 DrawIO XML。
本地版本怎么安装?先安装 Python 3.10+ 和支持 CUDA 的 PyTorch,克隆仓库并运行 scripts/setupsam3.sh,然后从 ModelScope 或 Hugging Face 下载 sam3.pt 放到 models/ 目录,并在 config.yaml 里指定模型路径。处理单张图片用 python main.py -i yourfile.png。
文字识别是在本地跑,还是走云端?OCR 完全在本地运行:Tesseract 离线即可使用,中英混排等复杂文本可以改用 PaddleOCR,公式则由 Pix2Text 转成 LaTeX。完全不依赖外部 API 的本地 VLM 目前还只是路线图上的规划。
安装时有什么坑需要提前知道?paddlepaddle 请固定在 3.2.2 版本(3.3.0 有已知 bug),或者退回用 Tesseract。RMBG 背景去除功能是可选的,而且要先通过它的安装脚本下载之后才能使用。
我可以商用吗?README 写明项目采用 Apache 2.0 协议,允许在保留版权声明的前提下商用和二次开发。不过要注意,GitHub 上标注的仓库协议是 AGPL-3.0,商用前请先查看 LICENSE 文件确认。
想跑得流畅,必须要有支持 CUDA 的显卡吗?SAM3 阶段强烈建议使用支持 CUDA 的 GPU。也可以通过 sam3.device: cpu 用 CPU 模式运行,但 README 主要把它定位成 GPU 架构不匹配报错时的应急方案,而不是官方支持的默认配置。
还原出来的文件和原图能有多接近?演示效果承诺 1:1 还原形状的描边、填充和箭头样式(虚线、线宽),并保留原有的布局逻辑、配色和元素层级。每个元素都能单独选中,之后你可以换成 DrawIO 原生模板或重新排版。
处理一张图片时,内部是怎么运作的?微调过的 SAM 3 先分割出图表元素,文字提取同步并行进行——Tesseract OCR 负责找出文本框,高清裁剪区域则交给 Pix2Text 转成 LaTeX 公式——最后把空间信息和文字信息合并成一个 DrawIO XML 文件。
在线网页平台怎么收费?新注册用户赠送 10 个免费额度,之后按量付费;作者用这套额度制度来防止资源被滥用。自己部署这个仓库则完全免费,只需承担你自己的硬件成本。
后续还有哪些功能在路上?箭头与形状的智能关联功能正在开发中。自定义 DrawIO 模板导入、批量导出优化,以及不依赖外部 API 的本地 VLM 部署,都已列为规划中的功能。
大小
86 MB
星标
5.5K
更新
提交Nov 17
时长
10个月
提交 · 90 天