Spaces:
Sleeping
Sleeping
Nu Appleblossom
commited on
Commit
•
9e22acb
1
Parent(s):
1d51202
trying to get graphviz working
Browse files
app.py
CHANGED
@@ -53,7 +53,7 @@ class Config:
|
|
53 |
self.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
54 |
self.DTYPE = torch.float32
|
55 |
self.TOPK = 5
|
56 |
-
self.CUTOFF = 0.
|
57 |
self.OUTPUT_LENGTH = 20
|
58 |
self.SUB_TOKEN_ID = 23070 # Arbitrary token ID to overwrite with embedding (token = "OSS")
|
59 |
self.LOG_BASE = 10
|
@@ -321,14 +321,23 @@ def add_nodes_edges(dot, node, config, max_weight, min_weight, parent=None, is_r
|
|
321 |
add_nodes_edges(dot, child, config, max_weight, min_weight, parent=node_id, is_root=False, depth=depth+1, trim_cutoff=trim_cutoff)
|
322 |
|
323 |
def create_tree_diagram(data, config, max_weight, min_weight, trim_cutoff=0):
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
dot.attr(rankdir='LR', size='5040,5000', margin='0.06', nodesep='0.06', ranksep='1', dpi='120', bgcolor='white')
|
326 |
|
327 |
add_nodes_edges(dot, data, config, max_weight, min_weight, trim_cutoff=trim_cutoff)
|
328 |
|
329 |
# Save to a temporary file first
|
330 |
temp_filename = "temp_tree_diagram"
|
331 |
-
dot.render(temp_filename, format='png', cleanup=True
|
332 |
|
333 |
# Read the file back into a BytesIO object
|
334 |
with open(f"{temp_filename}.png", "rb") as f:
|
@@ -348,6 +357,7 @@ def create_tree_diagram(data, config, max_weight, min_weight, trim_cutoff=0):
|
|
348 |
|
349 |
|
350 |
|
|
|
351 |
# Global variables to store loaded resources
|
352 |
tokenizer = None
|
353 |
model = None
|
|
|
53 |
self.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
54 |
self.DTYPE = torch.float32
|
55 |
self.TOPK = 5
|
56 |
+
self.CUTOFF = 0.0001 # Cumulative probability cutoff for tree branches
|
57 |
self.OUTPUT_LENGTH = 20
|
58 |
self.SUB_TOKEN_ID = 23070 # Arbitrary token ID to overwrite with embedding (token = "OSS")
|
59 |
self.LOG_BASE = 10
|
|
|
321 |
add_nodes_edges(dot, child, config, max_weight, min_weight, parent=node_id, is_root=False, depth=depth+1, trim_cutoff=trim_cutoff)
|
322 |
|
323 |
def create_tree_diagram(data, config, max_weight, min_weight, trim_cutoff=0):
|
324 |
+
import os
|
325 |
+
from graphviz import Digraph
|
326 |
+
|
327 |
+
# Ensure the system can find the dot command
|
328 |
+
os.environ["PATH"] += os.pathsep + "/usr/bin"
|
329 |
+
|
330 |
+
# Initialize the Digraph object and explicitly set the dot command path
|
331 |
+
dot = Digraph(comment='Definition Tree', format='png', engine='dot')
|
332 |
+
dot.command = '/usr/bin/dot'
|
333 |
+
|
334 |
dot.attr(rankdir='LR', size='5040,5000', margin='0.06', nodesep='0.06', ranksep='1', dpi='120', bgcolor='white')
|
335 |
|
336 |
add_nodes_edges(dot, data, config, max_weight, min_weight, trim_cutoff=trim_cutoff)
|
337 |
|
338 |
# Save to a temporary file first
|
339 |
temp_filename = "temp_tree_diagram"
|
340 |
+
dot.render(temp_filename, format='png', cleanup=True)
|
341 |
|
342 |
# Read the file back into a BytesIO object
|
343 |
with open(f"{temp_filename}.png", "rb") as f:
|
|
|
357 |
|
358 |
|
359 |
|
360 |
+
|
361 |
# Global variables to store loaded resources
|
362 |
tokenizer = None
|
363 |
model = None
|