🚀 图表转代码智能体(DiagramAgent/Diagram_to_Code_Agent)
本智能体旨在将给定的图表(可视化表示)转换为相应的结构化代码,为自动化图表编辑、逆向工程等场景提供可靠支持。
🚀 快速开始
你可以按照以下步骤使用该智能体:
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
model = Qwen2VLForConditionalGeneration.from_pretrained(
"DiagramAgent/Diagram_to_Code_Agent", torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained("DiagramAgent/Diagram_to_Code_Agent")
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "your input",
},
{"type": "text", "text": "image path"},
],
}
]
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
generated_ids = model.generate(**inputs, max_new_tokens=8192)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
✨ 主要特性
- 功能强大:能够将现有的图表转换为结构化的代码表示,支持图表编辑工作流程,捕捉并保留图表的隐式逻辑结构和视觉细节。
- 应用广泛:可应用于自动化图表编辑、可视化图表的逆向工程以及增强数据可视化工具等场景。
- 架构先进:基于Qwen2-VL-7B模型进行训练,与检查智能体紧密协作,确保生成代码的准确性。
📚 详细文档
模型概述
- 名称:DiagramAgent/Diagram_to_Code_Agent
- 描述:该智能体的任务是将给定的图表(可视化表示)转换为相应的结构化代码。
预期用途
- 主要任务:
- 将现有图表转换为结构化代码表示。
- 为图表编辑工作流程提供可靠的代码基础,支持修改操作。
- 捕捉并保留图表的隐式逻辑结构和视觉细节。
- 应用场景:
- 自动化图表编辑:将图表转换为代码,以便进行后续修改。
- 可视化图表的逆向工程:用于分析和复用。
- 增强数据可视化工具:通过集成基于代码的图表表示。
架构和训练细节
- 基础模型:使用Qwen2-VL-7B模型,这是一个视觉语言融合模型。
- 训练过程:
- 在DiagramGenBenchmark数据集中的各种图表样本上进行训练。
- 目标是生成与参考代码高度一致的代码,确保准确捕捉所有图表元素。
- 使用专门的损失函数来减少生成代码与参考代码之间的编辑距离。
- 模块交互:与检查智能体紧密协作,该智能体验证生成的代码并提供反馈以进行进一步优化。
信息表格
属性 |
详情 |
模型类型 |
视觉问答模型 |
训练数据 |
DiagramAgent/DiagramGenBenchmark |
基础模型 |
Qwen/Qwen2-VL-7B-Instruct |
论文链接 |
📑paper link |
📄 许可证
本项目采用Apache-2.0许可证。
📚 引用
如果你觉得我们的工作有帮助,请引用以下论文:
@inproceedings{wei2024wordsstructuredvisualsbenchmark,
title={From Words to Structured Visuals: A Benchmark and Framework for Text-to-Diagram Generation and Editing},
author={Jingxuan Wei and Cheng Tan and Qi Chen and Gaowei Wu and Siyuan Li and Zhangyang Gao and Linzhuang Sun and Bihui Yu and Ruifeng Guo},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
year={2025}
}