Update concept_map_generator.py
Browse files- concept_map_generator.py +4 -5
concept_map_generator.py
CHANGED
|
@@ -4,7 +4,7 @@ from tempfile import NamedTemporaryFile
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
-
def generate_concept_map(json_input: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a concept map from JSON input.
|
| 10 |
|
|
@@ -217,10 +217,9 @@ def generate_concept_map(json_input: str) -> str: # Removed base_color parameter
|
|
| 217 |
# Add child nodes and edges recursively starting from depth 1
|
| 218 |
add_nodes_and_edges(dot, 'central', data.get('nodes', []), current_depth=1, base_color=base_color)
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
return tmp.name + '.png'
|
| 224 |
|
| 225 |
except json.JSONDecodeError:
|
| 226 |
return "Error: Invalid JSON format"
|
|
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
+
def generate_concept_map(json_input: str, output_format: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a concept map from JSON input.
|
| 10 |
|
|
|
|
| 217 |
# Add child nodes and edges recursively starting from depth 1
|
| 218 |
add_nodes_and_edges(dot, 'central', data.get('nodes', []), current_depth=1, base_color=base_color)
|
| 219 |
|
| 220 |
+
with NamedTemporaryFile(delete=False, suffix=f'.{output_format}') as tmp:
|
| 221 |
+
dot.render(tmp.name, format=output_format, cleanup=True)
|
| 222 |
+
return f"{tmp.name}.{output_format}"
|
|
|
|
| 223 |
|
| 224 |
except json.JSONDecodeError:
|
| 225 |
return "Error: Invalid JSON format"
|