AnatoliiG commited on
Commit
4058c1e
·
1 Parent(s): 1a33f7a

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +62 -51
ui.py CHANGED
@@ -6,25 +6,38 @@ import config
6
  from model import engine
7
  from utils import sanitize_content
8
 
9
- # --- CSS стили ---
10
  CUSTOM_CSS = """
 
11
  .gradio-container {
12
  width: 100% !important;
13
  height: 100vh !important;
14
- max_width: 100% !important;
15
- margin: 0 !important;
16
  padding: 0 !important;
17
- display: flex;
18
- flex-direction: column;
 
 
 
 
 
 
 
 
 
 
19
  }
 
 
20
  #chatbot {
21
- height: 80vh !important;
22
- min-height: 500px !important;
23
- flex-grow: 1;
24
- overflow: auto;
25
- font-family: 'Consolas', 'Monaco', monospace;
26
  }
27
- footer { visibility: hidden !important; }
 
 
28
  """
29
 
30
  # --- Логика событий ---
@@ -33,17 +46,14 @@ footer { visibility: hidden !important; }
33
  def user_input(user_message, history):
34
  if not user_message:
35
  return None, history
36
-
37
  if history is None:
38
  history = []
39
 
40
- # Очистка старой истории
41
  clean_history = []
42
  for msg in history:
43
  clean_history.append(
44
  {"role": msg["role"], "content": sanitize_content(msg.get("content", ""))}
45
  )
46
-
47
  clean_history.append({"role": "user", "content": str(user_message)})
48
  return "", clean_history
49
 
@@ -54,7 +64,6 @@ def bot_response(history, system_prompt, temperature, max_tokens):
54
  yield history
55
  return
56
 
57
- # Подготовка сообщений
58
  messages = [{"role": "system", "content": system_prompt}]
59
  relevant_history = history[-15:] if len(history) > 15 else history
60
 
@@ -72,7 +81,6 @@ def bot_response(history, system_prompt, temperature, max_tokens):
72
  temperature=temperature,
73
  stream=True,
74
  )
75
-
76
  partial_text = ""
77
  for chunk in stream:
78
  delta = chunk["choices"][0]["delta"]
@@ -108,44 +116,47 @@ def create_ui():
108
  with gr.Blocks(
109
  theme=theme, css=CUSTOM_CSS, title="Qwen Coder Pro", fill_height=True
110
  ) as demo:
111
- with gr.Sidebar():
112
- gr.Markdown("### ⚙️ Settings")
113
- system_prompt = gr.Textbox(
114
- label="System Prompt",
115
- value="You are an expert coding assistant. Write clean, efficient code.",
116
- lines=5,
117
- )
118
- temperature = gr.Slider(
119
- 0.0, 1.0, value=config.DEFAULT_TEMP, label="Temperature"
120
- )
121
- max_tokens = gr.Slider(
122
- 512, 8192, value=config.DEFAULT_MAX_TOKENS, label="Max Tokens"
123
- )
124
- clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
125
-
126
- # Основная колонка
127
- with gr.Column(scale=1):
128
- chatbot = gr.Chatbot(
129
- label="Code Assistant",
130
- elem_id="chatbot",
131
- avatar_images=(None, "https://api.iconify.design/noto:robot.svg"),
132
- scale=1,
133
- )
134
-
135
- with gr.Row(variant="compact"):
136
- msg = gr.Textbox(
137
- show_label=False,
138
- placeholder="Type your code question here...",
139
- lines=1,
140
- scale=8,
141
- autofocus=True,
142
- max_lines=3,
143
  )
144
- submit_btn = gr.Button(
145
- "Run ➤", variant="primary", scale=1, min_width=100
 
 
 
 
 
 
 
146
  )
147
 
148
- # Chains
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  submit_event = (
150
  msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False)
151
  .then(lambda: set_interactive(False), None, [msg, submit_btn], queue=False)
 
6
  from model import engine
7
  from utils import sanitize_content
8
 
 
9
  CUSTOM_CSS = """
10
+ /* Убираем отступы у основного контейнера и растягиваем его */
11
  .gradio-container {
12
  width: 100% !important;
13
  height: 100vh !important;
14
+ max_height: 100vh !important;
 
15
  padding: 0 !important;
16
+ margin: 0 !important;
17
+ overflow: hidden !important;
18
+ }
19
+
20
+ /* Настройка главной колонки чата */
21
+ #main-col {
22
+ height: 100% !important;
23
+ max_height: 100vh !important;
24
+ display: flex !important;
25
+ flex-direction: column !important;
26
+ justify-content: space-between !important; /* Распределяем пространство */
27
+ padding-bottom: 10px !important;
28
  }
29
+
30
+ /* Сам чатбот - он должен расти (flex-grow) и иметь скролл */
31
  #chatbot {
32
+ flex-grow: 1 !important; /* Занимает всё доступное место */
33
+ height: auto !important;
34
+ min-height: 0 !important; /* Важно для работы скролла во flex-контейнере */
35
+ overflow-y: auto !important;
36
+ margin-bottom: 10px !important;
37
  }
38
+
39
+ /* Скрываем футер */
40
+ footer { display: none !important; }
41
  """
42
 
43
  # --- Логика событий ---
 
46
  def user_input(user_message, history):
47
  if not user_message:
48
  return None, history
 
49
  if history is None:
50
  history = []
51
 
 
52
  clean_history = []
53
  for msg in history:
54
  clean_history.append(
55
  {"role": msg["role"], "content": sanitize_content(msg.get("content", ""))}
56
  )
 
57
  clean_history.append({"role": "user", "content": str(user_message)})
58
  return "", clean_history
59
 
 
64
  yield history
65
  return
66
 
 
67
  messages = [{"role": "system", "content": system_prompt}]
68
  relevant_history = history[-15:] if len(history) > 15 else history
69
 
 
81
  temperature=temperature,
82
  stream=True,
83
  )
 
84
  partial_text = ""
85
  for chunk in stream:
86
  delta = chunk["choices"][0]["delta"]
 
116
  with gr.Blocks(
117
  theme=theme, css=CUSTOM_CSS, title="Qwen Coder Pro", fill_height=True
118
  ) as demo:
119
+ with gr.Row(elem_id="main-row", variant="panel"):
120
+ # Боковая панель
121
+ with gr.Sidebar():
122
+ gr.Markdown("### ⚙️ Settings")
123
+ system_prompt = gr.Textbox(
124
+ label="System Prompt",
125
+ value="You are an expert coding assistant. Write clean, efficient code.",
126
+ lines=5,
127
+ )
128
+ temperature = gr.Slider(
129
+ 0.0, 1.0, value=config.DEFAULT_TEMP, label="Temperature"
130
+ )
131
+ max_tokens = gr.Slider(
132
+ 512, 8192, value=config.DEFAULT_MAX_TOKENS, label="Max Tokens"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  )
134
+ clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
135
+
136
+ with gr.Column(scale=1, elem_id="main-col"):
137
+ chatbot = gr.Chatbot(
138
+ label="Code Assistant",
139
+ elem_id="chatbot",
140
+ avatar_images=(None, "https://api.iconify.design/noto:robot.svg"),
141
+ type="messages",
142
+ scale=1,
143
  )
144
 
145
+ # Группа ввода
146
+ with gr.Row(variant="compact", elem_id="input-row"):
147
+ msg = gr.Textbox(
148
+ show_label=False,
149
+ placeholder="Type your code question here...",
150
+ lines=1,
151
+ scale=8,
152
+ autofocus=True,
153
+ max_lines=5,
154
+ )
155
+ submit_btn = gr.Button(
156
+ "Run ➤", variant="primary", scale=1, min_width=100
157
+ )
158
+
159
+ # Chains (События)
160
  submit_event = (
161
  msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False)
162
  .then(lambda: set_interactive(False), None, [msg, submit_btn], queue=False)