From f074162334f6e2c0e88430cf0a057ee8ba000df0 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Sun, 29 Sep 2024 09:45:47 -0700 Subject: [PATCH] Add Graphviz test file (#1368) --- source/graphviz.js | 36 ++++++++++++++++++++++++++++++++++++ source/view.js | 1 + test/models.json | 8 ++++++++ 3 files changed, 45 insertions(+) create mode 100644 source/graphviz.js diff --git a/source/graphviz.js b/source/graphviz.js new file mode 100644 index 0000000000..b0cf0537ad --- /dev/null +++ b/source/graphviz.js @@ -0,0 +1,36 @@ + +const graphviz = {}; + +graphviz.ModelFactory = class { + + match(context) { + const reader = context.read('text', 0x10000); + if (reader) { + try { + const line = reader.read('\n'); + if (line === undefined) { + return; + } + if (line.indexOf('digraph') !== -1) { + context.type = 'graphviz.dot'; + } + } catch { + // continue regardless of error + } + } + } + + async open(/* context */) { + throw new graphviz.Error('Invalid file content. File contains Graphviz data.'); + } +}; + +graphviz.Error = class extends Error { + + constructor(message) { + super(message); + this.name = 'Error loading Graphviz model.'; + } +}; + +export const ModelFactory = graphviz.ModelFactory; diff --git a/source/view.js b/source/view.js index 5602646f72..b93a5da58c 100644 --- a/source/view.js +++ b/source/view.js @@ -5778,6 +5778,7 @@ view.ModelFactoryService = class { this.register('./safetensors', ['.safetensors', '.safetensors.index.json']); this.register('./tvm', ['.json', '.params']); this.register('./modular', ['.maxviz']); + this.register('./graphviz', ['.dot']); this.register('./catboost', ['.cbm']); this.register('./weka', ['.model']); this.register('./qnn', ['.json', '.bin', '.serialized']); diff --git a/test/models.json b/test/models.json index c0a7f2966e..1a268b590f 100644 --- a/test/models.json +++ b/test/models.json @@ -2088,6 +2088,14 @@ "format": "Flux", "link": "https://github.com/lutzroeder/netron/issues/334" }, + { + "type": "graphviz", + "target": "resnet18.dot", + "source": "https://github.com/user-attachments/files/17175694/resnet18.dot.zip[resnet18.dot]", + "format": "Graphviz", + "error": "Invalid file content. File contains Graphviz data.", + "link": "https://github.com/lutzroeder/netron/issues/1368" + }, { "type": "gguf", "target": "mixtral-8x7b-v0.1.Q4_K_M.gguf",