AnatoliiG commited on
Commit ·
49dd18b
1
Parent(s): 4c14f1d
Update ui.py
Browse files
ui.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
--- START OF FILE ui.py ---
|
| 2 |
-
|
| 3 |
import traceback
|
|
|
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
import config
|
| 6 |
from model import engine
|
| 7 |
from utils import get_clean_text
|
|
@@ -61,6 +61,7 @@ footer { display: none !important; }
|
|
| 61 |
|
| 62 |
# --- Логика событий ---
|
| 63 |
|
|
|
|
| 64 |
def user_input(user_message, history):
|
| 65 |
if not user_message:
|
| 66 |
return None, history
|
|
@@ -115,20 +116,23 @@ def bot_response(history, system_prompt, temperature, max_tokens):
|
|
| 115 |
|
| 116 |
def set_interactive(is_interactive):
|
| 117 |
return (
|
| 118 |
-
gr.update(
|
|
|
|
|
|
|
|
|
|
| 119 |
gr.update(interactive=is_interactive),
|
| 120 |
)
|
| 121 |
|
| 122 |
|
| 123 |
# --- Создание интерфейса ---
|
| 124 |
|
|
|
|
| 125 |
def create_ui():
|
| 126 |
theme = gr.themes.Soft(primary_hue="blue", text_size="lg")
|
| 127 |
|
| 128 |
with gr.Blocks(theme=theme, css=CUSTOM_CSS, title="Qwen Coder Pro") as demo:
|
| 129 |
# fill_height=True помогает растянуть layout
|
| 130 |
with gr.Row(equal_height=True, variant="default", elem_classes=["main-row"]):
|
| 131 |
-
|
| 132 |
# --- Боковая панель ---
|
| 133 |
with gr.Sidebar(elem_classes=["sidebar"]):
|
| 134 |
gr.Markdown("### ⚙️ Settings")
|
|
@@ -137,13 +141,16 @@ def create_ui():
|
|
| 137 |
value="You are an expert coding assistant. Write clean, efficient code.",
|
| 138 |
lines=5,
|
| 139 |
)
|
| 140 |
-
temperature = gr.Slider(
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
|
| 143 |
|
| 144 |
# --- Основная колонка (Чат + Ввод) ---
|
| 145 |
with gr.Column(scale=1, elem_classes=["main-chat-col"]):
|
| 146 |
-
|
| 147 |
chatbot = gr.Chatbot(
|
| 148 |
label="Code Assistant",
|
| 149 |
elem_id="chatbot",
|
|
@@ -160,22 +167,28 @@ def create_ui():
|
|
| 160 |
scale=9,
|
| 161 |
autofocus=True,
|
| 162 |
max_lines=10,
|
| 163 |
-
container=False
|
|
|
|
|
|
|
|
|
|
| 164 |
)
|
| 165 |
-
submit_btn = gr.Button("Run ➤", variant="primary", scale=1, min_width=80)
|
| 166 |
|
| 167 |
# --- Привязка событий ---
|
| 168 |
submit_event = (
|
| 169 |
msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False)
|
| 170 |
.then(lambda: set_interactive(False), None, [msg, submit_btn], queue=False)
|
| 171 |
-
.then(
|
|
|
|
|
|
|
| 172 |
.then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
|
| 173 |
)
|
| 174 |
|
| 175 |
click_event = (
|
| 176 |
submit_btn.click(user_input, [msg, chatbot], [msg, chatbot], queue=False)
|
| 177 |
.then(lambda: set_interactive(False), None, [msg, submit_btn], queue=False)
|
| 178 |
-
.then(
|
|
|
|
|
|
|
| 179 |
.then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
|
| 180 |
)
|
| 181 |
|
|
|
|
|
|
|
|
|
|
| 1 |
import traceback
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
+
|
| 5 |
import config
|
| 6 |
from model import engine
|
| 7 |
from utils import get_clean_text
|
|
|
|
| 61 |
|
| 62 |
# --- Логика событий ---
|
| 63 |
|
| 64 |
+
|
| 65 |
def user_input(user_message, history):
|
| 66 |
if not user_message:
|
| 67 |
return None, history
|
|
|
|
| 116 |
|
| 117 |
def set_interactive(is_interactive):
|
| 118 |
return (
|
| 119 |
+
gr.update(
|
| 120 |
+
interactive=is_interactive,
|
| 121 |
+
placeholder="Wait..." if not is_interactive else "Type code question...",
|
| 122 |
+
),
|
| 123 |
gr.update(interactive=is_interactive),
|
| 124 |
)
|
| 125 |
|
| 126 |
|
| 127 |
# --- Создание интерфейса ---
|
| 128 |
|
| 129 |
+
|
| 130 |
def create_ui():
|
| 131 |
theme = gr.themes.Soft(primary_hue="blue", text_size="lg")
|
| 132 |
|
| 133 |
with gr.Blocks(theme=theme, css=CUSTOM_CSS, title="Qwen Coder Pro") as demo:
|
| 134 |
# fill_height=True помогает растянуть layout
|
| 135 |
with gr.Row(equal_height=True, variant="default", elem_classes=["main-row"]):
|
|
|
|
| 136 |
# --- Боковая панель ---
|
| 137 |
with gr.Sidebar(elem_classes=["sidebar"]):
|
| 138 |
gr.Markdown("### ⚙️ Settings")
|
|
|
|
| 141 |
value="You are an expert coding assistant. Write clean, efficient code.",
|
| 142 |
lines=5,
|
| 143 |
)
|
| 144 |
+
temperature = gr.Slider(
|
| 145 |
+
0.0, 1.0, value=config.DEFAULT_TEMP, label="Temperature"
|
| 146 |
+
)
|
| 147 |
+
max_tokens = gr.Slider(
|
| 148 |
+
512, 8192, value=config.DEFAULT_MAX_TOKENS, label="Max Tokens"
|
| 149 |
+
)
|
| 150 |
clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
|
| 151 |
|
| 152 |
# --- Основная колонка (Чат + Ввод) ---
|
| 153 |
with gr.Column(scale=1, elem_classes=["main-chat-col"]):
|
|
|
|
| 154 |
chatbot = gr.Chatbot(
|
| 155 |
label="Code Assistant",
|
| 156 |
elem_id="chatbot",
|
|
|
|
| 167 |
scale=9,
|
| 168 |
autofocus=True,
|
| 169 |
max_lines=10,
|
| 170 |
+
container=False,
|
| 171 |
+
)
|
| 172 |
+
submit_btn = gr.Button(
|
| 173 |
+
"Run ➤", variant="primary", scale=1, min_width=80
|
| 174 |
)
|
|
|
|
| 175 |
|
| 176 |
# --- Привязка событий ---
|
| 177 |
submit_event = (
|
| 178 |
msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False)
|
| 179 |
.then(lambda: set_interactive(False), None, [msg, submit_btn], queue=False)
|
| 180 |
+
.then(
|
| 181 |
+
bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
|
| 182 |
+
)
|
| 183 |
.then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
|
| 184 |
)
|
| 185 |
|
| 186 |
click_event = (
|
| 187 |
submit_btn.click(user_input, [msg, chatbot], [msg, chatbot], queue=False)
|
| 188 |
.then(lambda: set_interactive(False), None, [msg, submit_btn], queue=False)
|
| 189 |
+
.then(
|
| 190 |
+
bot_response, [chatbot, system_prompt, temperature, max_tokens], chatbot
|
| 191 |
+
)
|
| 192 |
.then(lambda: set_interactive(True), None, [msg, submit_btn], queue=False)
|
| 193 |
)
|
| 194 |
|