Update app.py
Browse files
app.py
CHANGED
|
@@ -54,12 +54,10 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 54 |
name='ConceptMap',
|
| 55 |
format='png',
|
| 56 |
graph_attr={
|
| 57 |
-
'rankdir': 'TB', # Top-to-Bottom
|
| 58 |
-
'splines': 'ortho', #
|
| 59 |
'bgcolor': 'white', # Fondo blanco
|
| 60 |
-
'pad': '0.5'
|
| 61 |
-
'ranksep': '1.8', # ¡Aumenta la separación vertical entre niveles! (más alto)
|
| 62 |
-
'ratio': '1.2' # ¡Relación de aspecto (altura/anchura)! >1 para más alto que ancho
|
| 63 |
}
|
| 64 |
)
|
| 65 |
|
|
@@ -80,7 +78,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 80 |
# Helper function to recursively add nodes and edges
|
| 81 |
def add_nodes_and_edges(parent_id, nodes_list, current_depth=0):
|
| 82 |
# Calculate color for current depth, making it lighter
|
| 83 |
-
lightening_factor = 0.12
|
| 84 |
|
| 85 |
# Convert base_color hex to RGB
|
| 86 |
base_r = int(base_color[1:3], 16)
|
|
@@ -102,8 +100,9 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 102 |
# Font color: white for dark nodes, black for very light nodes
|
| 103 |
font_color = 'white' if current_depth * lightening_factor < 0.6 else 'black'
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
|
|
|
| 107 |
edge_font_size = max(7, 10 - (current_depth * 1))
|
| 108 |
|
| 109 |
for node in nodes_list:
|
|
@@ -117,8 +116,8 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 117 |
dot.node(
|
| 118 |
node_id,
|
| 119 |
label,
|
| 120 |
-
shape='box',
|
| 121 |
-
style='filled,rounded',
|
| 122 |
fillcolor=node_fill_color,
|
| 123 |
fontcolor=font_color,
|
| 124 |
fontsize=str(font_size)
|
|
@@ -129,7 +128,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 129 |
node_id,
|
| 130 |
label=relationship,
|
| 131 |
color=edge_color,
|
| 132 |
-
fontcolor=edge_color,
|
| 133 |
fontsize=str(edge_font_size)
|
| 134 |
)
|
| 135 |
|
|
@@ -137,7 +136,7 @@ def generate_concept_map(json_input: str) -> str:
|
|
| 137 |
add_nodes_and_edges(node_id, node['subnodes'], current_depth + 1)
|
| 138 |
|
| 139 |
# Start processing from the top-level nodes connected to the central node
|
| 140 |
-
add_nodes_and_edges('central', data.get('nodes', []), current_depth=1)
|
| 141 |
|
| 142 |
# Save to temporary file
|
| 143 |
with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
|
|
@@ -163,8 +162,8 @@ if __name__ == "__main__":
|
|
| 163 |
type="filepath",
|
| 164 |
show_download_button=True
|
| 165 |
),
|
| 166 |
-
title="AI Concept Map (
|
| 167 |
-
description="Generates an AI concept map with custom rounded boxes, color gradient, white background
|
| 168 |
)
|
| 169 |
|
| 170 |
demo.launch(
|
|
|
|
| 54 |
name='ConceptMap',
|
| 55 |
format='png',
|
| 56 |
graph_attr={
|
| 57 |
+
'rankdir': 'TB', # Top-to-Bottom
|
| 58 |
+
'splines': 'ortho', # Straight lines
|
| 59 |
'bgcolor': 'white', # Fondo blanco
|
| 60 |
+
'pad': '0.5' # ¡Este es el margen! 0.5 pulgadas
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
)
|
| 63 |
|
|
|
|
| 78 |
# Helper function to recursively add nodes and edges
|
| 79 |
def add_nodes_and_edges(parent_id, nodes_list, current_depth=0):
|
| 80 |
# Calculate color for current depth, making it lighter
|
| 81 |
+
lightening_factor = 0.12 # How much lighter each level gets
|
| 82 |
|
| 83 |
# Convert base_color hex to RGB
|
| 84 |
base_r = int(base_color[1:3], 16)
|
|
|
|
| 100 |
# Font color: white for dark nodes, black for very light nodes
|
| 101 |
font_color = 'white' if current_depth * lightening_factor < 0.6 else 'black'
|
| 102 |
|
| 103 |
+
# Edge colors can remain constant or change. Let's make them slightly visible.
|
| 104 |
+
edge_color = '#4a4a4a' # Un gris oscuro para las líneas
|
| 105 |
+
font_size = max(9, 14 - (current_depth * 2)) # Adjust font size based on depth
|
| 106 |
edge_font_size = max(7, 10 - (current_depth * 1))
|
| 107 |
|
| 108 |
for node in nodes_list:
|
|
|
|
| 116 |
dot.node(
|
| 117 |
node_id,
|
| 118 |
label,
|
| 119 |
+
shape='box', # Rectángulo
|
| 120 |
+
style='filled,rounded', # Redondeado
|
| 121 |
fillcolor=node_fill_color,
|
| 122 |
fontcolor=font_color,
|
| 123 |
fontsize=str(font_size)
|
|
|
|
| 128 |
node_id,
|
| 129 |
label=relationship,
|
| 130 |
color=edge_color,
|
| 131 |
+
fontcolor=edge_color, # Color de la fuente de la arista también gris
|
| 132 |
fontsize=str(edge_font_size)
|
| 133 |
)
|
| 134 |
|
|
|
|
| 136 |
add_nodes_and_edges(node_id, node['subnodes'], current_depth + 1)
|
| 137 |
|
| 138 |
# Start processing from the top-level nodes connected to the central node
|
| 139 |
+
add_nodes_and_edges('central', data.get('nodes', []), current_depth=1) # Initial depth is 1 for nodes under central
|
| 140 |
|
| 141 |
# Save to temporary file
|
| 142 |
with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
|
|
|
|
| 162 |
type="filepath",
|
| 163 |
show_download_button=True
|
| 164 |
),
|
| 165 |
+
title="AI Concept Map (Custom Style)",
|
| 166 |
+
description="Generates an AI concept map with custom rounded boxes, color gradient, and white background."
|
| 167 |
)
|
| 168 |
|
| 169 |
demo.launch(
|