Romanchello-bit commited on
Commit
8aef1af
·
1 Parent(s): 2ba3545

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -41
app.py CHANGED
@@ -200,56 +200,57 @@ def draw_graph(graph_data, current_node, predicted_path):
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
@@ -356,7 +357,10 @@ elif st.session_state.page == "chat":
356
  curr_id = node_to_id[st.session_state.current_node]
357
  target_id = node_to_id["close_deal"] # Fixed: using close_deal from sales_script.json
358
  path = get_predicted_path(graph, curr_id, target_id, id_to_node, node_to_id)
359
- st.graphviz_chart(draw_graph(graph_data, st.session_state.current_node, path))
 
 
 
360
 
361
  with col_chat:
362
  for msg in st.session_state.messages:
 
200
 
201
  dot = graphviz.Digraph()
202
 
203
+ # --- НАЛАШТУВАННЯ ГЕОМЕТРІЇ (Compact Mode) ---
204
+ dot.attr(
205
+ rankdir='TB', # Зверху вниз
206
+ splines='ortho', # Ламані лінії (прямі кути)
207
+ nodesep='0.3', # Мінімальний відступ збоку
208
+ ranksep='0.4', # Мінімальний відступ знизу (робить граф коротшим)
209
+ bgcolor='transparent' # Прозорий фон, щоб зливався з темою
210
+ )
211
 
212
+ # --- СТИЛЬ БЛОКІВ (Wide & Slim) ---
213
+ # shape='note' виглядає як документ, або 'box' для суворості
214
+ # fixedsize='false' дозволяє блоку розтягуватись під текст, але ми задаємо мінімальну ширину
215
+ dot.attr('node',
216
+ shape='box',
217
+ style='rounded,filled',
218
+ fontname='Arial',
219
+ fontsize='11',
220
+ width='2.5', # Робимо їх широкими
221
+ height='0.5', # Робимо їх низькими
222
+ margin='0.1' # Менше полів всередині блоку
223
+ )
224
 
225
+ # --- СТИЛЬ ЛІНІЙ ---
226
+ dot.attr('edge', fontname='Arial', fontsize='9', arrowsize='0.6')
227
+
228
  for n in nodes:
229
+ # Базовий стиль (Світло-сірий, непомітний)
230
+ fill = '#F7F9F9'; color = '#BDC3C7'; pen = '1'; font = '#424949'
 
 
 
231
 
232
+ # Поточний крок (Червоний акцент)
233
+ if n == current_node:
234
+ fill = '#FF4B4B'; color = '#922B21'; pen = '2'; font = 'white'
 
 
 
235
 
236
+ # Золотий шлях (Жовтий підсвіт)
237
+ elif n in predicted_path:
238
+ fill = '#FEF9E7'; color = '#F1C40F'; pen = '1'; font = 'black'
 
 
239
 
240
+ # Малюємо вузол
241
+ dot.node(n, label=n, fillcolor=fill, color=color, penwidth=pen, fontcolor=font)
242
 
 
243
  for e in edges:
244
+ color = '#D5D8DC'; pen = '1' # Дуже світлі лінії за замовчуванням
 
245
 
246
+ # Підсвітка шляху
247
  if e["from"] in predicted_path and e["to"] in predicted_path:
248
+ try:
249
+ # Перевіряємо послідовність
250
+ if predicted_path.index(e["to"]) == predicted_path.index(e["from"]) + 1:
251
+ color = '#F1C40F'; pen = '2.5' # Жирна золота лінія
252
+ except: pass
253
+
 
 
 
 
254
  dot.edge(e["from"], e["to"], color=color, penwidth=pen)
255
 
256
  return dot
 
357
  curr_id = node_to_id[st.session_state.current_node]
358
  target_id = node_to_id["close_deal"] # Fixed: using close_deal from sales_script.json
359
  path = get_predicted_path(graph, curr_id, target_id, id_to_node, node_to_id)
360
+ st.graphviz_chart(
361
+ draw_graph(graph_data, st.session_state.current_node, path),
362
+ use_container_width=True # Розтягує граф на всю ширину колонки
363
+ )
364
 
365
  with col_chat:
366
  for msg in st.session_state.messages: