Update concept_map_generator.py
Browse files- concept_map_generator.py +12 -136
concept_map_generator.py
CHANGED
|
@@ -4,13 +4,18 @@ 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 |
|
| 11 |
Args:
|
| 12 |
json_input (str): A JSON string describing the concept map structure.
|
| 13 |
It must follow the Expected JSON Format Example below.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
Expected JSON Format Example:
|
| 16 |
{
|
|
@@ -26,33 +31,8 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 26 |
"label": "Deep Learning",
|
| 27 |
"relationship": "for example",
|
| 28 |
"subnodes": [
|
| 29 |
-
{
|
| 30 |
-
|
| 31 |
-
"label": "CNNs",
|
| 32 |
-
"relationship": "for example"
|
| 33 |
-
},
|
| 34 |
-
{
|
| 35 |
-
"id": "rnn_example",
|
| 36 |
-
"label": "RNNs",
|
| 37 |
-
"relationship": "for example"
|
| 38 |
-
}
|
| 39 |
-
]
|
| 40 |
-
},
|
| 41 |
-
{
|
| 42 |
-
"id": "rl_branch",
|
| 43 |
-
"label": "Reinforcement Learning",
|
| 44 |
-
"relationship": "for example",
|
| 45 |
-
"subnodes": [
|
| 46 |
-
{
|
| 47 |
-
"id": "qlearning_example",
|
| 48 |
-
"label": "Q-Learning",
|
| 49 |
-
"relationship": "example"
|
| 50 |
-
},
|
| 51 |
-
{
|
| 52 |
-
"id": "pg_example",
|
| 53 |
-
"label": "Policy Gradients",
|
| 54 |
-
"relationship": "example"
|
| 55 |
-
}
|
| 56 |
]
|
| 57 |
}
|
| 58 |
]
|
|
@@ -67,119 +47,13 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 67 |
"label": "AGI",
|
| 68 |
"relationship": "this is",
|
| 69 |
"subnodes": [
|
| 70 |
-
{
|
| 71 |
-
"id": "strong_ai",
|
| 72 |
-
"label": "Strong AI",
|
| 73 |
-
"relationship": "provoked by",
|
| 74 |
-
"subnodes": [
|
| 75 |
-
{
|
| 76 |
-
"id": "human_intel",
|
| 77 |
-
"label": "Human-level Intel.",
|
| 78 |
-
"relationship": "of"
|
| 79 |
-
}
|
| 80 |
-
]
|
| 81 |
-
}
|
| 82 |
-
]
|
| 83 |
-
},
|
| 84 |
-
{
|
| 85 |
-
"id": "ani_type",
|
| 86 |
-
"label": "ANI",
|
| 87 |
-
"relationship": "this is",
|
| 88 |
-
"subnodes": [
|
| 89 |
-
{
|
| 90 |
-
"id": "weak_ai",
|
| 91 |
-
"label": "Weak AI",
|
| 92 |
-
"relationship": "provoked by",
|
| 93 |
-
"subnodes": [
|
| 94 |
-
{
|
| 95 |
-
"id": "narrow_tasks",
|
| 96 |
-
"label": "Narrow Tasks",
|
| 97 |
-
"relationship": "of"
|
| 98 |
-
}
|
| 99 |
-
]
|
| 100 |
-
}
|
| 101 |
-
]
|
| 102 |
-
}
|
| 103 |
-
]
|
| 104 |
-
},
|
| 105 |
-
{
|
| 106 |
-
"id": "ai_capabilities",
|
| 107 |
-
"label": "Capabilities",
|
| 108 |
-
"relationship": "change",
|
| 109 |
-
"subnodes": [
|
| 110 |
-
{
|
| 111 |
-
"id": "data_proc",
|
| 112 |
-
"label": "Data Processing",
|
| 113 |
-
"relationship": "can",
|
| 114 |
-
"subnodes": [
|
| 115 |
-
{
|
| 116 |
-
"id": "big_data",
|
| 117 |
-
"label": "Big Data",
|
| 118 |
-
"relationship": "as",
|
| 119 |
-
"subnodes": [
|
| 120 |
-
{
|
| 121 |
-
"id": "analysis_example",
|
| 122 |
-
"label": "Data Analysis",
|
| 123 |
-
"relationship": "example"
|
| 124 |
-
},
|
| 125 |
-
{
|
| 126 |
-
"id": "prediction_example",
|
| 127 |
-
"label": "Prediction",
|
| 128 |
-
"relationship": "example"
|
| 129 |
-
}
|
| 130 |
-
]
|
| 131 |
-
}
|
| 132 |
-
]
|
| 133 |
-
},
|
| 134 |
-
{
|
| 135 |
-
"id": "decision_making",
|
| 136 |
-
"label": "Decision Making",
|
| 137 |
-
"relationship": "can be",
|
| 138 |
-
"subnodes": [
|
| 139 |
-
{
|
| 140 |
-
"id": "automation",
|
| 141 |
-
"label": "Automation",
|
| 142 |
-
"relationship": "as",
|
| 143 |
-
"subnodes": [
|
| 144 |
-
{
|
| 145 |
-
"id": "robotics_example",
|
| 146 |
-
"label": "Robotics",
|
| 147 |
-
"relationship": "Example"},
|
| 148 |
-
{
|
| 149 |
-
"id": "autonomous_example",
|
| 150 |
-
"label": "Autonomous Vehicles",
|
| 151 |
-
"relationship": "of one"
|
| 152 |
-
}
|
| 153 |
-
]
|
| 154 |
-
}
|
| 155 |
-
]
|
| 156 |
-
},
|
| 157 |
-
{
|
| 158 |
-
"id": "problem_solving",
|
| 159 |
-
"label": "Problem Solving",
|
| 160 |
-
"relationship": "can",
|
| 161 |
-
"subnodes": [
|
| 162 |
-
{
|
| 163 |
-
"id": "optimization",
|
| 164 |
-
"label": "Optimization",
|
| 165 |
-
"relationship": "as is",
|
| 166 |
-
"subnodes": [
|
| 167 |
-
{
|
| 168 |
-
"id": "algorithms_example",
|
| 169 |
-
"label": "Algorithms",
|
| 170 |
-
"relationship": "for example"
|
| 171 |
-
}
|
| 172 |
-
]
|
| 173 |
-
}
|
| 174 |
]
|
| 175 |
}
|
| 176 |
]
|
| 177 |
}
|
| 178 |
]
|
| 179 |
}
|
| 180 |
-
|
| 181 |
-
Returns:
|
| 182 |
-
str: The filepath to the generated PNG image file.
|
| 183 |
"""
|
| 184 |
try:
|
| 185 |
if not json_input.strip():
|
|
@@ -201,7 +75,9 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 201 |
}
|
| 202 |
)
|
| 203 |
|
| 204 |
-
|
|
|
|
|
|
|
| 205 |
|
| 206 |
# Central node styling (rounded box, dark color)
|
| 207 |
dot.node(
|
|
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
+
def generate_concept_map(json_input: str, base_color: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a concept map from JSON input.
|
| 10 |
|
| 11 |
Args:
|
| 12 |
json_input (str): A JSON string describing the concept map structure.
|
| 13 |
It must follow the Expected JSON Format Example below.
|
| 14 |
+
base_color (str): The hexadecimal color string (e.g., '#19191a') for the base
|
| 15 |
+
color of the nodes, from which a gradient will be generated.
|
| 16 |
+
|
| 17 |
+
Returns:
|
| 18 |
+
str: The filepath to the generated PNG image file.
|
| 19 |
|
| 20 |
Expected JSON Format Example:
|
| 21 |
{
|
|
|
|
| 31 |
"label": "Deep Learning",
|
| 32 |
"relationship": "for example",
|
| 33 |
"subnodes": [
|
| 34 |
+
{"id": "cnn_example", "label": "CNNs", "relationship": "for example"},
|
| 35 |
+
{"id": "rnn_example", "label": "RNNs", "relationship": "for example"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
]
|
| 37 |
}
|
| 38 |
]
|
|
|
|
| 47 |
"label": "AGI",
|
| 48 |
"relationship": "this is",
|
| 49 |
"subnodes": [
|
| 50 |
+
{"id": "strong_ai", "label": "Strong AI", "relationship": "provoked by"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
]
|
| 52 |
}
|
| 53 |
]
|
| 54 |
}
|
| 55 |
]
|
| 56 |
}
|
|
|
|
|
|
|
|
|
|
| 57 |
"""
|
| 58 |
try:
|
| 59 |
if not json_input.strip():
|
|
|
|
| 75 |
}
|
| 76 |
)
|
| 77 |
|
| 78 |
+
# Ensure base_color is valid, fallback if not
|
| 79 |
+
if not isinstance(base_color, str) or not base_color.startswith('#') or len(base_color) != 7:
|
| 80 |
+
base_color = '#19191a' # Fallback to default dark if invalid
|
| 81 |
|
| 82 |
# Central node styling (rounded box, dark color)
|
| 83 |
dot.node(
|