Update radial_diagram_generator.py
Browse files- radial_diagram_generator.py +34 -43
radial_diagram_generator.py
CHANGED
|
@@ -4,68 +4,57 @@ from tempfile import NamedTemporaryFile
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
-
def generate_radial_diagram(json_input: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a radial (center-expanded) diagram from JSON input.
|
| 10 |
|
| 11 |
Args:
|
| 12 |
json_input (str): A JSON string describing the radial diagram structure.
|
| 13 |
It must follow the Expected JSON Format Example below.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
Expected JSON Format Example:
|
| 16 |
{
|
| 17 |
-
"central_node": "
|
| 18 |
"nodes": [
|
| 19 |
{
|
| 20 |
-
"id": "
|
| 21 |
-
"label": "
|
| 22 |
-
"relationship": "
|
| 23 |
-
"subnodes": [
|
| 24 |
-
{"id": "supervised_l", "label": "Supervised Learning", "relationship": "e.g."},
|
| 25 |
-
{"id": "unsupervised_l", "label": "Unsupervised Learning", "relationship": "e.g."}
|
| 26 |
-
]
|
| 27 |
-
},
|
| 28 |
-
{
|
| 29 |
-
"id": "dl_architectures",
|
| 30 |
-
"label": "Deep Learning Arch.",
|
| 31 |
-
"relationship": "evolved from",
|
| 32 |
-
"subnodes": [
|
| 33 |
-
{"id": "cnns_rad", "label": "CNNs", "relationship": "e.g."},
|
| 34 |
-
{"id": "rnns_rad", "label": "RNNs", "relationship": "e.g."}
|
| 35 |
-
]
|
| 36 |
-
},
|
| 37 |
-
{
|
| 38 |
-
"id": "major_applications",
|
| 39 |
-
"label": "Major AI Applications",
|
| 40 |
-
"relationship": "applied in",
|
| 41 |
-
"subnodes": [
|
| 42 |
-
{"id": "nlp_rad", "label": "Natural Language Processing", "relationship": "e.g."},
|
| 43 |
-
{"id": "cv_rad", "label": "Computer Vision", "relationship": "e.g."}
|
| 44 |
-
]
|
| 45 |
-
},
|
| 46 |
-
{
|
| 47 |
-
"id": "ethical_concerns",
|
| 48 |
-
"label": "Ethical AI Concerns",
|
| 49 |
-
"relationship": "addresses",
|
| 50 |
"subnodes": [
|
| 51 |
-
{
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
]
|
| 54 |
},
|
| 55 |
{
|
| 56 |
-
"id": "
|
| 57 |
-
"label": "
|
| 58 |
-
"relationship": "
|
| 59 |
"subnodes": [
|
| 60 |
-
{
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
]
|
| 63 |
}
|
| 64 |
]
|
| 65 |
}
|
| 66 |
-
|
| 67 |
-
Returns:
|
| 68 |
-
str: The filepath to the generated PNG image file.
|
| 69 |
"""
|
| 70 |
try:
|
| 71 |
if not json_input.strip():
|
|
@@ -92,7 +81,9 @@ def generate_radial_diagram(json_input: str) -> str:
|
|
| 92 |
}
|
| 93 |
)
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Central node styling (rounded box, dark color)
|
| 98 |
dot.node(
|
|
|
|
| 4 |
import os
|
| 5 |
from graph_generator_utils import add_nodes_and_edges
|
| 6 |
|
| 7 |
+
def generate_radial_diagram(json_input: str, base_color: str) -> str:
|
| 8 |
"""
|
| 9 |
Generates a radial (center-expanded) diagram from JSON input.
|
| 10 |
|
| 11 |
Args:
|
| 12 |
json_input (str): A JSON string describing the radial diagram 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 |
{
|
| 22 |
+
"central_node": "Making Coffee",
|
| 23 |
"nodes": [
|
| 24 |
{
|
| 25 |
+
"id": "coffee_components",
|
| 26 |
+
"label": "Coffee Components",
|
| 27 |
+
"relationship": "Involves",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"subnodes": [
|
| 29 |
+
{
|
| 30 |
+
"id": "equipment",
|
| 31 |
+
"label": "Equipment Needed",
|
| 32 |
+
"relationship": "Requires",
|
| 33 |
+
"subnodes": [
|
| 34 |
+
{"id": "coffee_maker", "label": "Coffee Maker", "relationship": "e.g."},
|
| 35 |
+
{"id": "mug", "label": "Mug", "relationship": "For"}
|
| 36 |
+
]
|
| 37 |
+
}
|
| 38 |
]
|
| 39 |
},
|
| 40 |
{
|
| 41 |
+
"id": "coffee_process_enjoyment",
|
| 42 |
+
"label": "Process & Enjoyment",
|
| 43 |
+
"relationship": "Leads to",
|
| 44 |
"subnodes": [
|
| 45 |
+
{
|
| 46 |
+
"id": "preparation_steps",
|
| 47 |
+
"label": "Preparation Steps",
|
| 48 |
+
"relationship": "Involves",
|
| 49 |
+
"subnodes": [
|
| 50 |
+
{"id": "grind_beans", "label": "Grind Beans", "relationship": "Step 1 (if whole)"},
|
| 51 |
+
{"id": "heat_water", "label": "Heat Water", "relationship": "Step 2"}
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
]
|
| 55 |
}
|
| 56 |
]
|
| 57 |
}
|
|
|
|
|
|
|
|
|
|
| 58 |
"""
|
| 59 |
try:
|
| 60 |
if not json_input.strip():
|
|
|
|
| 81 |
}
|
| 82 |
)
|
| 83 |
|
| 84 |
+
# Ensure base_color is valid, fallback if not
|
| 85 |
+
if not isinstance(base_color, str) or not base_color.startswith('#') or len(base_color) != 7:
|
| 86 |
+
base_color = '#19191a' # Fallback to default dark if invalid
|
| 87 |
|
| 88 |
# Central node styling (rounded box, dark color)
|
| 89 |
dot.node(
|