AnatoliiG commited on
Commit
9be7e63
·
1 Parent(s): 7497eb4
Files changed (2) hide show
  1. styles.py +31 -26
  2. ui.py +9 -15
styles.py CHANGED
@@ -1,5 +1,5 @@
1
  CSS = """
2
- /* Убираем лишние отступы у всего приложения */
3
  .gradio-container {
4
  width: 100% !important;
5
  height: 100vh !important;
@@ -8,55 +8,60 @@ CSS = """
8
  overflow: hidden !important;
9
  }
10
 
11
- /* Сайдбар на всю высоту */
 
 
 
 
 
 
 
12
  .sidebar {
13
  height: 100vh !important;
14
  border-right: 1px solid var(--border-color-primary) !important;
 
15
  }
16
 
17
- /*
18
- ГЛАВНАЯ КОЛОНКА (ID: col-chat-main)
19
- Превращаем её во Flex-контейнер.
20
- Она занимает 100% высоты экрана.
21
- */
22
  #col-chat-main {
23
  height: 100vh !important;
24
- max-height: 100vh !important;
25
  display: flex !important;
26
  flex-direction: column !important;
27
- justify-content: space-between !important;
28
  padding: 0 !important;
29
  margin: 0 !important;
30
  border: none !important;
 
31
  }
32
 
33
- /*
34
- ЧАТБОТ (ID: chatbot)
35
- flex-grow: 1 -> Заставляет чат занять всё доступное пространство.
36
- min-height: 0 -> КРИТИЧНО для работы скролла внутри flex-элемента.
37
  */
38
  #chatbot {
39
  flex-grow: 1 !important;
40
- height: auto !important;
41
- min-height: 0 !important;
42
- overflow-y: auto !important;
43
- margin: 0 !important;
44
  border: none !important;
45
- border-radius: 0 !important;
46
- padding-bottom: 10px !important;
47
  }
48
 
49
- /*
50
- ЗОНА ВВОДА (ID: input-area)
51
- flex-shrink: 0 -> Запрещаем сжиматься.
52
- Прижимается к низу автоматически из-за flex-grow у чата.
53
- */
 
 
 
54
  #input-area {
55
- flex-shrink: 0 !important;
 
56
  padding: 15px !important;
57
  background: var(--background-fill-secondary);
58
  border-top: 1px solid var(--border-color-primary);
59
- width: 100% !important;
60
  }
61
 
62
  /* Убираем футер */
 
1
  CSS = """
2
+ /* 1. Глобальный контейнер на весь экран без скроллов страницы */
3
  .gradio-container {
4
  width: 100% !important;
5
  height: 100vh !important;
 
8
  overflow: hidden !important;
9
  }
10
 
11
+ /* 2. Основной ряд (Sidebar + Chat) тоже должен быть во весь экран */
12
+ #main-row {
13
+ height: 100vh !important;
14
+ max-height: 100vh !important;
15
+ overflow: hidden !important;
16
+ }
17
+
18
+ /* 3. Сайдбар */
19
  .sidebar {
20
  height: 100vh !important;
21
  border-right: 1px solid var(--border-color-primary) !important;
22
+ overflow-y: auto !important;
23
  }
24
 
25
+ /* 4. Правая колонка (Чат + Ввод) */
 
 
 
 
26
  #col-chat-main {
27
  height: 100vh !important;
 
28
  display: flex !important;
29
  flex-direction: column !important;
 
30
  padding: 0 !important;
31
  margin: 0 !important;
32
  border: none !important;
33
+ gap: 0 !important; /* Убираем промежутки между чатом и вводом */
34
  }
35
 
36
+ /* 5. ЧАТБОТ - САМОЕ ВАЖНОЕ
37
+ height: 0 + flex-grow: 1 заставляет его занять всё место,
38
+ даже если сообщений мало.
 
39
  */
40
  #chatbot {
41
  flex-grow: 1 !important;
42
+ height: 0 !important; /* Хак для Flexbox */
43
+ min-height: 0 !important; /* Разрешает сжиматься/растягиваться */
44
+ width: 100% !important;
45
+ overflow-y: auto !important; /* Скролл внутри */
46
  border: none !important;
47
+ margin: 0 !important;
 
48
  }
49
 
50
+ /* Обертка чата внутри Gradio (иногда создает проблемы, фиксим её) */
51
+ #chatbot > .wrapper {
52
+ height: 100% !important;
53
+ display: flex !important;
54
+ flex-direction: column !important;
55
+ }
56
+
57
+ /* 6. Поле ввода */
58
  #input-area {
59
+ flex-shrink: 0 !important; /* Не даем сжиматься */
60
+ width: 100% !important;
61
  padding: 15px !important;
62
  background: var(--background-fill-secondary);
63
  border-top: 1px solid var(--border-color-primary);
64
+ z-index: 10; /* Чтобы быть поверх */
65
  }
66
 
67
  /* Убираем футер */
ui.py CHANGED
@@ -8,12 +8,11 @@ from styles import CSS
8
  def create_ui():
9
  theme = gr.themes.Soft(primary_hue="blue", text_size="lg")
10
 
11
- # fill_height=True помогает Gradio понять, что мы хотим на весь экран
12
- with gr.Blocks(
13
- theme=theme, css=CSS, title="Qwen Coder Pro", fill_height=True
14
- ) as demo:
15
- with gr.Row(equal_height=True, variant="default", elem_classes=["main-row"]):
16
- # --- ЛЕВАЯ КОЛОНКА (НАСТРОЙКИ) ---
17
  with gr.Sidebar(elem_classes=["sidebar"]):
18
  gr.Markdown("### ⚙️ Settings")
19
  system_prompt = gr.Textbox(
@@ -29,20 +28,18 @@ def create_ui():
29
  )
30
  clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
31
 
32
- # --- ПРАВАЯ КОЛОНКА (ЧАТ + ВВОД) ---
33
- # elem_id="col-chat-main" связывает эту колонку с Flexbox-стилями в styles.py
34
  with gr.Column(scale=1, elem_id="col-chat-main"):
35
- # 1. Чат (растянется благодаря flex-grow: 1 в CSS)
36
  chatbot = gr.Chatbot(
37
- elem_id="chatbot", # Важно для CSS
38
  label="Code Assistant",
39
  avatar_images=(None, "https://api.iconify.design/noto:robot.svg"),
40
  layout="bubble",
41
  render_markdown=True,
42
- scale=1,
43
  )
44
 
45
- # 2. Зона ввода (прижмется к низу)
46
  with gr.Row(elem_id="input-area"):
47
  msg = gr.Textbox(
48
  show_label=False,
@@ -58,21 +55,18 @@ def create_ui():
58
  )
59
 
60
  # --- СОБЫТИЯ ---
61
- # Enter в поле ввода
62
  msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(
63
  lambda: set_interactive(False), None, [msg, submit_btn], queue=False
64
  ).then(
65
  bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
66
  ).then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
67
 
68
- # Клик по кнопке Run
69
  submit_btn.click(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(
70
  lambda: set_interactive(False), None, [msg, submit_btn], queue=False
71
  ).then(
72
  bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
73
  ).then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
74
 
75
- # Очистка
76
  clear_btn.click(lambda: [], None, chatbot, queue=False)
77
 
78
  return demo
 
8
  def create_ui():
9
  theme = gr.themes.Soft(primary_hue="blue", text_size="lg")
10
 
11
+ # Убрали fill_height=True, полагаемся на наш CSS
12
+ with gr.Blocks(theme=theme, css=CSS, title="Code LLM") as demo:
13
+ # Добавили elem_id="main-row"
14
+ with gr.Row(equal_height=True, variant="default", elem_id="main-row"):
15
+ # --- ЛЕВАЯ КОЛОНКА ---
 
16
  with gr.Sidebar(elem_classes=["sidebar"]):
17
  gr.Markdown("### ⚙️ Settings")
18
  system_prompt = gr.Textbox(
 
28
  )
29
  clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
30
 
31
+ # --- ПРАВАЯ КОЛОНКА ---
 
32
  with gr.Column(scale=1, elem_id="col-chat-main"):
33
+ # Чатбот
34
  chatbot = gr.Chatbot(
35
+ elem_id="chatbot",
36
  label="Code Assistant",
37
  avatar_images=(None, "https://api.iconify.design/noto:robot.svg"),
38
  layout="bubble",
39
  render_markdown=True,
 
40
  )
41
 
42
+ # Поле ввода
43
  with gr.Row(elem_id="input-area"):
44
  msg = gr.Textbox(
45
  show_label=False,
 
55
  )
56
 
57
  # --- СОБЫТИЯ ---
 
58
  msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(
59
  lambda: set_interactive(False), None, [msg, submit_btn], queue=False
60
  ).then(
61
  bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
62
  ).then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
63
 
 
64
  submit_btn.click(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(
65
  lambda: set_interactive(False), None, [msg, submit_btn], queue=False
66
  ).then(
67
  bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
68
  ).then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
69
 
 
70
  clear_btn.click(lambda: [], None, chatbot, queue=False)
71
 
72
  return demo