Update app.py
Browse files
app.py
CHANGED
|
@@ -9,19 +9,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 9 |
|
| 10 |
Args:
|
| 11 |
json_input (str): JSON describing the concept map structure.
|
| 12 |
-
|
| 13 |
-
{
|
| 14 |
-
"central_node": "Main concept",
|
| 15 |
-
"nodes": [
|
| 16 |
-
{
|
| 17 |
-
"id": "unique_identifier",
|
| 18 |
-
"label": "Node label",
|
| 19 |
-
"relationship": "Relationship to parent",
|
| 20 |
-
"subnodes": [...] # Optional
|
| 21 |
-
}
|
| 22 |
-
]
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
Returns:
|
| 26 |
str: Base64 data URL of the generated concept map
|
| 27 |
"""
|
|
@@ -45,7 +33,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 45 |
}
|
| 46 |
)
|
| 47 |
|
| 48 |
-
# Central node
|
| 49 |
dot.node(
|
| 50 |
'central',
|
| 51 |
data['central_node'],
|
|
@@ -56,7 +44,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 56 |
fontsize='14'
|
| 57 |
)
|
| 58 |
|
| 59 |
-
# Process nodes
|
| 60 |
for node in data['nodes']:
|
| 61 |
node_id = node.get('id')
|
| 62 |
label = node.get('label')
|
|
@@ -66,7 +54,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 66 |
if not all([node_id, label, relationship]):
|
| 67 |
raise ValueError(f"Invalid node: {node}")
|
| 68 |
|
| 69 |
-
# Create main node
|
| 70 |
dot.node(
|
| 71 |
node_id,
|
| 72 |
label,
|
|
@@ -86,7 +74,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 86 |
fontsize='10'
|
| 87 |
)
|
| 88 |
|
| 89 |
-
# Process subnodes
|
| 90 |
for subnode in node.get('subnodes', []):
|
| 91 |
sub_id = subnode.get('id')
|
| 92 |
sub_label = subnode.get('label')
|
|
@@ -98,9 +86,9 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 98 |
dot.node(
|
| 99 |
sub_id,
|
| 100 |
sub_label,
|
| 101 |
-
shape='
|
| 102 |
style='filled',
|
| 103 |
-
fillcolor='#
|
| 104 |
fontcolor='white',
|
| 105 |
fontsize='10'
|
| 106 |
)
|
|
@@ -134,8 +122,24 @@ if __name__ == "__main__":
|
|
| 134 |
"label": "Machine Learning",
|
| 135 |
"relationship": "core_component",
|
| 136 |
"subnodes": [
|
| 137 |
-
{
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
]
|
| 140 |
},
|
| 141 |
{
|
|
@@ -143,8 +147,40 @@ if __name__ == "__main__":
|
|
| 143 |
"label": "Natural Language Processing",
|
| 144 |
"relationship": "application_area",
|
| 145 |
"subnodes": [
|
| 146 |
-
{
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
]
|
| 149 |
}
|
| 150 |
]
|
|
@@ -159,12 +195,13 @@ if __name__ == "__main__":
|
|
| 159 |
label="JSON Input",
|
| 160 |
lines=15
|
| 161 |
),
|
| 162 |
-
outputs=gr.
|
| 163 |
-
label="
|
| 164 |
-
|
|
|
|
| 165 |
),
|
| 166 |
-
title="Concept Map Generator",
|
| 167 |
-
description="Create concept maps from JSON
|
| 168 |
)
|
| 169 |
|
| 170 |
demo.launch(
|
|
|
|
| 9 |
|
| 10 |
Args:
|
| 11 |
json_input (str): JSON describing the concept map structure.
|
| 12 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
Returns:
|
| 14 |
str: Base64 data URL of the generated concept map
|
| 15 |
"""
|
|
|
|
| 33 |
}
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# Central node (ellipse)
|
| 37 |
dot.node(
|
| 38 |
'central',
|
| 39 |
data['central_node'],
|
|
|
|
| 44 |
fontsize='14'
|
| 45 |
)
|
| 46 |
|
| 47 |
+
# Process nodes (rectangles)
|
| 48 |
for node in data['nodes']:
|
| 49 |
node_id = node.get('id')
|
| 50 |
label = node.get('label')
|
|
|
|
| 54 |
if not all([node_id, label, relationship]):
|
| 55 |
raise ValueError(f"Invalid node: {node}")
|
| 56 |
|
| 57 |
+
# Create main node (rectangle)
|
| 58 |
dot.node(
|
| 59 |
node_id,
|
| 60 |
label,
|
|
|
|
| 74 |
fontsize='10'
|
| 75 |
)
|
| 76 |
|
| 77 |
+
# Process subnodes (rectangles with lighter fill)
|
| 78 |
for subnode in node.get('subnodes', []):
|
| 79 |
sub_id = subnode.get('id')
|
| 80 |
sub_label = subnode.get('label')
|
|
|
|
| 86 |
dot.node(
|
| 87 |
sub_id,
|
| 88 |
sub_label,
|
| 89 |
+
shape='box',
|
| 90 |
style='filled',
|
| 91 |
+
fillcolor='#FFA726',
|
| 92 |
fontcolor='white',
|
| 93 |
fontsize='10'
|
| 94 |
)
|
|
|
|
| 122 |
"label": "Machine Learning",
|
| 123 |
"relationship": "core_component",
|
| 124 |
"subnodes": [
|
| 125 |
+
{
|
| 126 |
+
"id": "sl",
|
| 127 |
+
"label": "Supervised Learning",
|
| 128 |
+
"relationship": "type_of",
|
| 129 |
+
"subnodes": [
|
| 130 |
+
{"id": "reg", "label": "Regression", "relationship": "technique"},
|
| 131 |
+
{"id": "clf", "label": "Classification", "relationship": "technique"}
|
| 132 |
+
]
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"id": "ul",
|
| 136 |
+
"label": "Unsupervised Learning",
|
| 137 |
+
"relationship": "type_of",
|
| 138 |
+
"subnodes": [
|
| 139 |
+
{"id": "clus", "label": "Clustering", "relationship": "technique"},
|
| 140 |
+
{"id": "dim", "label": "Dimensionality Reduction", "relationship": "technique"}
|
| 141 |
+
]
|
| 142 |
+
}
|
| 143 |
]
|
| 144 |
},
|
| 145 |
{
|
|
|
|
| 147 |
"label": "Natural Language Processing",
|
| 148 |
"relationship": "application_area",
|
| 149 |
"subnodes": [
|
| 150 |
+
{
|
| 151 |
+
"id": "sa",
|
| 152 |
+
"label": "Sentiment Analysis",
|
| 153 |
+
"relationship": "task",
|
| 154 |
+
"subnodes": [
|
| 155 |
+
{"id": "tc", "label": "Text Classification", "relationship": "method"},
|
| 156 |
+
{"id": "absa", "label": "Aspect-Based Sentiment Analysis", "relationship": "method"}
|
| 157 |
+
]
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"id": "tr",
|
| 161 |
+
"label": "Translation",
|
| 162 |
+
"relationship": "task",
|
| 163 |
+
"subnodes": [
|
| 164 |
+
{"id": "nmt", "label": "Neural Machine Translation", "relationship": "method"},
|
| 165 |
+
{"id": "rbt", "label": "Rule-Based Translation", "relationship": "method"}
|
| 166 |
+
]
|
| 167 |
+
}
|
| 168 |
+
]
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"id": "cv",
|
| 172 |
+
"label": "Computer Vision",
|
| 173 |
+
"relationship": "application_area",
|
| 174 |
+
"subnodes": [
|
| 175 |
+
{
|
| 176 |
+
"id": "od",
|
| 177 |
+
"label": "Object Detection",
|
| 178 |
+
"relationship": "task",
|
| 179 |
+
"subnodes": [
|
| 180 |
+
{"id": "yolo", "label": "YOLO", "relationship": "algorithm"},
|
| 181 |
+
{"id": "rcnn", "label": "R-CNN", "relationship": "algorithm"}
|
| 182 |
+
]
|
| 183 |
+
}
|
| 184 |
]
|
| 185 |
}
|
| 186 |
]
|
|
|
|
| 195 |
label="JSON Input",
|
| 196 |
lines=15
|
| 197 |
),
|
| 198 |
+
outputs=gr.Image(
|
| 199 |
+
label="Concept Map",
|
| 200 |
+
type="filepath",
|
| 201 |
+
interactive=False
|
| 202 |
),
|
| 203 |
+
title="Advanced Concept Map Generator",
|
| 204 |
+
description="Create complex concept maps from JSON with direct image output"
|
| 205 |
)
|
| 206 |
|
| 207 |
demo.launch(
|