ZahirJS commited on
Commit
5b8a84b
·
verified ·
1 Parent(s): 51148e0

Update synoptic_chart_generator.py

Browse files
Files changed (1) hide show
  1. synoptic_chart_generator.py +17 -55
synoptic_chart_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_synoptic_chart(json_input: str) -> str:
8
  """
9
  Generates a synoptic chart (horizontal flowchart) from JSON input.
10
 
11
  Args:
12
  json_input (str): A JSON string describing the synoptic chart structure.
13
  It must follow the Expected JSON Format Example below.
 
 
 
 
 
14
 
15
  Expected JSON Format Example:
16
  {
@@ -19,24 +24,15 @@ def generate_synoptic_chart(json_input: str) -> str:
19
  {
20
  "id": "phase1",
21
  "label": "I. Problem Definition & Data Acquisition",
22
- "relationship": "Starts with",
23
  "subnodes": [
24
  {
25
  "id": "sub1_1",
26
  "label": "1. Problem Formulation",
27
- "relationship": "Involves",
28
- "subnodes": [
29
- {"id": "sub1_1_1", "label": "1.1. Identify Business Need", "relationship": "e.g."},
30
- {"id": "sub1_1_2", "label": "1.2. Define KPIs", "relationship": "e.g."}
31
- ]
32
- },
33
- {
34
- "id": "sub1_2",
35
- "label": "2. Data Collection",
36
- "relationship": "Followed by",
37
  "subnodes": [
38
- {"id": "sub1_2_1", "label": "2.1. Source Data", "relationship": "from"},
39
- {"id": "sub1_2_2", "label": "2.2. Data Cleaning", "relationship": "includes"}
40
  ]
41
  }
42
  ]
@@ -44,58 +40,20 @@ def generate_synoptic_chart(json_input: str) -> str:
44
  {
45
  "id": "phase2",
46
  "label": "II. Model Development",
47
- "relationship": "Proceeds to",
48
  "subnodes": [
49
  {
50
  "id": "sub2_1",
51
  "label": "1. Feature Engineering",
52
- "relationship": "Comprises",
53
- "subnodes": [
54
- {"id": "sub2_1_1", "label": "1.1. Feature Selection", "relationship": "e.g."},
55
- {"id": "sub2_1_2", "label": "1.2. Feature Transformation", "relationship": "e.g."}
56
- ]
57
- },
58
- {
59
- "id": "sub2_2",
60
- "label": "2. Model Training",
61
- "relationship": "Involves",
62
- "subnodes": [
63
- {"id": "sub2_2_1", "label": "2.1. Algorithm Selection", "relationship": "uses"},
64
- {"id": "sub2_2_2", "label": "2.2. Hyperparameter Tuning", "relationship": "optimizes"}
65
- ]
66
- }
67
- ]
68
- },
69
- {
70
- "id": "phase3",
71
- "label": "III. Evaluation & Deployment",
72
- "relationship": "Culminates in",
73
- "subnodes": [
74
- {
75
- "id": "sub3_1",
76
- "label": "1. Model Evaluation",
77
- "relationship": "Includes",
78
- "subnodes": [
79
- {"id": "sub3_1_1", "label": "1.1. Performance Metrics", "relationship": "measures"},
80
- {"id": "sub3_1_2", "label": "1.2. Bias & Fairness Audits", "relationship": "ensures"}
81
- ]
82
- },
83
- {
84
- "id": "sub3_2",
85
- "label": "2. Deployment & Monitoring",
86
- "relationship": "Requires",
87
  "subnodes": [
88
- {"id": "sub3_2_1", "label": "2.1. API/Integration Development", "relationship": "for"},
89
- {"id": "sub3_2_2", "label": "2.2. Continuous Monitoring", "relationship": "ensures"}
90
  ]
91
  }
92
  ]
93
  }
94
  ]
95
  }
96
-
97
- Returns:
98
- str: The filepath to the generated PNG image file.
99
  """
100
  try:
101
  if not json_input.strip():
@@ -119,6 +77,10 @@ def generate_synoptic_chart(json_input: str) -> str:
119
  }
120
  )
121
 
 
 
 
 
122
  base_color = '#19191a' # Base color for the central node and gradient
123
 
124
  # Central node styling (rounded box, dark color)
 
4
  import os
5
  from graph_generator_utils import add_nodes_and_edges
6
 
7
+ def generate_synoptic_chart(json_input: str, base_color: str) -> str:
8
  """
9
  Generates a synoptic chart (horizontal flowchart) from JSON input.
10
 
11
  Args:
12
  json_input (str): A JSON string describing the synoptic chart 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
  {
 
24
  {
25
  "id": "phase1",
26
  "label": "I. Problem Definition & Data Acquisition",
27
+ "relationship": "Starts\\nwith",
28
  "subnodes": [
29
  {
30
  "id": "sub1_1",
31
  "label": "1. Problem Formulation",
32
+ "relationship": "Involves\\n(Steps)",
 
 
 
 
 
 
 
 
 
33
  "subnodes": [
34
+ {"id": "sub1_1_1", "label": "1.1. Identify Business Need", "relationship": "e.g.\\n(Need)"},
35
+ {"id": "sub1_1_2", "label": "1.2. Define KPIs", "relationship": "e.g.\\n(Metrics)"}
36
  ]
37
  }
38
  ]
 
40
  {
41
  "id": "phase2",
42
  "label": "II. Model Development",
43
+ "relationship": "Proceeds\\nto",
44
  "subnodes": [
45
  {
46
  "id": "sub2_1",
47
  "label": "1. Feature Engineering",
48
+ "relationship": "Comprises\\n(Features)",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  "subnodes": [
50
+ {"id": "sub2_1_1", "label": "1.1. Feature Selection", "relationship": "e.g.\\n(Select)"}
 
51
  ]
52
  }
53
  ]
54
  }
55
  ]
56
  }
 
 
 
57
  """
58
  try:
59
  if not json_input.strip():
 
77
  }
78
  )
79
 
80
+ # Ensure base_color is valid, fallback if not
81
+ if not isinstance(base_color, str) or not base_color.startswith('#') or len(base_color) != 7:
82
+ base_color = '#19191a' # Fallback to default dark if invalid
83
+
84
  base_color = '#19191a' # Base color for the central node and gradient
85
 
86
  # Central node styling (rounded box, dark color)