Romanchello-bit commited on
Commit
2ba3545
·
1 Parent(s): 3d922e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -9
app.py CHANGED
@@ -197,20 +197,61 @@ def generate_response(model, context, user_input, intent, lead_info, archetype):
197
  def draw_graph(graph_data, current_node, predicted_path):
198
  nodes = graph_data[3]
199
  edges = graph_data[4]
 
200
  dot = graphviz.Digraph()
201
- dot.attr(rankdir='LR', splines='ortho')
202
- dot.attr('node', shape='box', style='rounded,filled', fontname='Arial', fontsize='10')
203
 
 
 
 
 
 
 
 
 
 
 
 
204
  for n in nodes:
205
- fill = '#F0F2F6'; color = '#BDC3C7'; pen = '1'
206
- if n == current_node: fill = '#FF4B4B'; color = 'black'; pen = '2'
207
- elif n in predicted_path: fill = '#FFF8E1'; color = '#F1C40F'
208
- dot.node(n, label=n, fillcolor=fill, color=color, penwidth=pen)
 
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  for e in edges:
211
- color = '#BDC3C7'
212
- if e["from"] in predicted_path and e["to"] in predicted_path: color = '#F1C40F'
213
- dot.edge(e["from"], e["to"], color=color)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  return dot
215
 
216
  # --- MAIN APP ---
 
197
  def draw_graph(graph_data, current_node, predicted_path):
198
  nodes = graph_data[3]
199
  edges = graph_data[4]
200
+
201
  dot = graphviz.Digraph()
 
 
202
 
203
+ # --- ГОЛОВНА ЗМІНА ТУТ ---
204
+ # rankdir='TB' -> Top to Bottom (Вертикально)
205
+ # splines='ortho' -> ламані лінії (прямі кути), виглядає охайніше
206
+ # nodesep='0.6' -> горизонтальний відступ між сусідніми вузлами
207
+ # ranksep='0.8' -> вертикальний відступ між рівнями
208
+ dot.attr(rankdir='TB', splines='ortho', nodesep='0.6', ranksep='0.8')
209
+
210
+ # Налаштування загального стилю вузлів для кращої читабельності
211
+ dot.attr('node', shape='box', style='rounded,filled', fontname='Arial', fontsize='11', height='0.6')
212
+
213
+ # Малюємо вузли
214
  for n in nodes:
215
+ # Базовий стиль (сірий)
216
+ fill = '#F0F2F6'
217
+ color = '#BDC3C7'
218
+ pen = '1'
219
+ fontcolor = 'black'
220
 
221
+ # Якщо це поточний вузол (Яскраво червоний)
222
+ if n == current_node:
223
+ fill = '#FF4B4B'
224
+ color = 'black'
225
+ pen = '3' # Товстіша рамка
226
+ fontcolor = 'white' # Білий текст на червоному фоні
227
+
228
+ # Якщо це частина "Золотого шляху" (Жовтий)
229
+ elif n in predicted_path:
230
+ fill = '#FFF8E1'
231
+ color = '#F1C40F'
232
+ pen = '2'
233
+
234
+ dot.node(n, label=n, fillcolor=fill, color=color, penwidth=pen, fontcolor=fontcolor)
235
+
236
+ # Малюємо ребра (стрілочки)
237
  for e in edges:
238
+ color = '#BDC3C7' # Базовий сірий для стрілок
239
+ pen = '1'
240
+
241
+ # Якщо стрілка веде по золотому шляху - підсвічуємо її
242
+ if e["from"] in predicted_path and e["to"] in predicted_path:
243
+ # Додаткова перевірка: підсвічуємо тільки якщо вони йдуть підряд у шляху
244
+ try:
245
+ idx1 = predicted_path.index(e["from"])
246
+ idx2 = predicted_path.index(e["to"])
247
+ if idx2 == idx1 + 1:
248
+ color = '#F1C40F' # Золотий
249
+ pen = '2'
250
+ except ValueError:
251
+ pass # Якщо раптом вузол не в списку, ігноруємо
252
+
253
+ dot.edge(e["from"], e["to"], color=color, penwidth=pen)
254
+
255
  return dot
256
 
257
  # --- MAIN APP ---