ZahirJS commited on
Commit
7a5d3f8
·
verified ·
1 Parent(s): b17e9c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -54,13 +54,12 @@ 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', # Straight lines
59
- 'bgcolor': 'white', # Fondo blanco
60
- 'pad': '0.5', # Margen alrededor del gráfico
61
- 'size': '8,12!', # ¡Nuevo! Tamaño deseado (ancho, alto en pulgadas). El '!' es importante.
62
- 'ranksep': '1.0' # ¡Nuevo! Aumenta la separación vertical entre niveles
63
- # 'ratio': 'fill' # Podría usarse con 'size' para forzar a rellenar el espacio
64
  }
65
  )
66
 
@@ -81,7 +80,7 @@ def generate_concept_map(json_input: str) -> str:
81
  # Helper function to recursively add nodes and edges
82
  def add_nodes_and_edges(parent_id, nodes_list, current_depth=0):
83
  # Calculate color for current depth, making it lighter
84
- lightening_factor = 0.12 # How much lighter each level gets
85
 
86
  # Convert base_color hex to RGB
87
  base_r = int(base_color[1:3], 16)
@@ -103,9 +102,8 @@ def generate_concept_map(json_input: str) -> str:
103
  # Font color: white for dark nodes, black for very light nodes
104
  font_color = 'white' if current_depth * lightening_factor < 0.6 else 'black'
105
 
106
- # Edge colors can remain constant or change. Let's make them slightly visible.
107
- edge_color = '#4a4a4a' # Un gris oscuro para las líneas
108
- font_size = max(9, 14 - (current_depth * 2)) # Adjust font size based on depth
109
  edge_font_size = max(7, 10 - (current_depth * 1))
110
 
111
  for node in nodes_list:
@@ -119,8 +117,8 @@ def generate_concept_map(json_input: str) -> str:
119
  dot.node(
120
  node_id,
121
  label,
122
- shape='box', # Rectángulo
123
- style='filled,rounded', # Redondeado
124
  fillcolor=node_fill_color,
125
  fontcolor=font_color,
126
  fontsize=str(font_size)
@@ -131,7 +129,7 @@ def generate_concept_map(json_input: str) -> str:
131
  node_id,
132
  label=relationship,
133
  color=edge_color,
134
- fontcolor=edge_color, # Color de la fuente de la arista también gris
135
  fontsize=str(edge_font_size)
136
  )
137
 
@@ -139,7 +137,7 @@ def generate_concept_map(json_input: str) -> str:
139
  add_nodes_and_edges(node_id, node['subnodes'], current_depth + 1)
140
 
141
  # Start processing from the top-level nodes connected to the central node
142
- add_nodes_and_edges('central', data.get('nodes', []), current_depth=1) # Initial depth is 1 for nodes under central
143
 
144
  # Save to temporary file
145
  with NamedTemporaryFile(delete=False, suffix='.png') as tmp:
@@ -165,8 +163,8 @@ if __name__ == "__main__":
165
  type="filepath",
166
  show_download_button=True
167
  ),
168
- title="AI Concept Map (Custom Style)",
169
- description="Generates an AI concept map with custom rounded boxes, color gradient, and white background."
170
  )
171
 
172
  demo.launch(
 
54
  name='ConceptMap',
55
  format='png',
56
  graph_attr={
57
+ 'rankdir': 'TB', # Top-to-Bottom (layout de arriba a abajo)
58
+ 'splines': 'ortho', # Líneas rectas
59
+ 'bgcolor': 'white', # Fondo blanco
60
+ 'pad': '0.5', # Margen interno (padding)
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
  # 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
  # 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
+ edge_color = '#4a4a4a'
106
+ font_size = max(9, 14 - (current_depth * 2))
 
107
  edge_font_size = max(7, 10 - (current_depth * 1))
108
 
109
  for node in nodes_list:
 
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
  node_id,
130
  label=relationship,
131
  color=edge_color,
132
+ fontcolor=edge_color,
133
  fontsize=str(edge_font_size)
134
  )
135
 
 
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
  type="filepath",
164
  show_download_button=True
165
  ),
166
+ title="AI Concept Map (Optimized Proportions)",
167
+ description="Generates an AI concept map with custom rounded boxes, color gradient, white background, and improved aspect ratio for vertical display."
168
  )
169
 
170
  demo.launch(