change interface
Browse files- api/fastapi_server.py +0 -2
- app.py +34 -50
api/fastapi_server.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import os
|
2 |
|
3 |
-
# Установка переменных окружения для кэша HuggingFace
|
4 |
#os.environ["TRANSFORMERS_CACHE"] = "cache/huggingface"
|
5 |
os.environ["HF_HOME"] = "cache/huggingface"
|
6 |
os.environ["HUGGINGFACE_HUB_CACHE"] = "cache/huggingface"
|
7 |
os.environ["XDG_CACHE_HOME"] = "cache"
|
8 |
|
9 |
-
# Создание необходимых директорий
|
10 |
os.makedirs("cache/huggingface", exist_ok=True)
|
11 |
|
12 |
import time
|
|
|
1 |
import os
|
2 |
|
|
|
3 |
#os.environ["TRANSFORMERS_CACHE"] = "cache/huggingface"
|
4 |
os.environ["HF_HOME"] = "cache/huggingface"
|
5 |
os.environ["HUGGINGFACE_HUB_CACHE"] = "cache/huggingface"
|
6 |
os.environ["XDG_CACHE_HOME"] = "cache"
|
7 |
|
|
|
8 |
os.makedirs("cache/huggingface", exist_ok=True)
|
9 |
|
10 |
import time
|
app.py
CHANGED
@@ -122,67 +122,51 @@ with gr.Blocks(title="Status Law Assistant", theme=gr.themes.Soft()) as demo:
|
|
122 |
gr.Markdown("# 🤖 Status Law Assistant")
|
123 |
|
124 |
with gr.Row():
|
125 |
-
|
126 |
-
|
127 |
-
build_kb_btn = gr.Button("Create/Update Knowledge Base", variant="primary")
|
128 |
-
check_status_btn = gr.Button("Check Status")
|
129 |
-
kb_status = gr.Textbox(
|
130 |
-
label="Knowledge Base Status",
|
131 |
-
value="Checking status...",
|
132 |
-
interactive=False
|
133 |
-
)
|
134 |
-
# Привязываем обе кнопки
|
135 |
-
build_kb_btn.click(build_kb, inputs=None, outputs=kb_status)
|
136 |
-
check_status_btn.click(check_kb_status, inputs=None, outputs=kb_status)
|
137 |
-
|
138 |
-
gr.Markdown("### 💬 Chat Interface")
|
139 |
-
conversation_id = gr.State(None)
|
140 |
-
|
141 |
-
with gr.Row():
|
142 |
-
with gr.Column(scale=2):
|
143 |
-
# Улучшенный интерфейс чата
|
144 |
chatbot = gr.Chatbot(
|
145 |
label="Conversation",
|
146 |
-
height=
|
147 |
show_label=False,
|
148 |
bubble_full_width=False
|
149 |
)
|
150 |
with gr.Row():
|
151 |
msg = gr.Textbox(
|
152 |
-
label="
|
153 |
-
placeholder="
|
154 |
scale=4
|
155 |
)
|
156 |
-
submit_btn = gr.Button("
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
return chat_history, conv_id
|
167 |
-
|
168 |
-
chat_history.append([message, ""])
|
169 |
-
response, new_conv_id = chat_with_api(message, conv_id)
|
170 |
-
chat_history[-1][1] = response
|
171 |
-
return chat_history, new_conv_id
|
172 |
|
173 |
-
#
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
186 |
|
187 |
if __name__ == "__main__":
|
188 |
# Launch Gradio interface
|
|
|
122 |
gr.Markdown("# 🤖 Status Law Assistant")
|
123 |
|
124 |
with gr.Row():
|
125 |
+
# Left column for chat (larger)
|
126 |
+
with gr.Column(scale=3):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
chatbot = gr.Chatbot(
|
128 |
label="Conversation",
|
129 |
+
height=600,
|
130 |
show_label=False,
|
131 |
bubble_full_width=False
|
132 |
)
|
133 |
with gr.Row():
|
134 |
msg = gr.Textbox(
|
135 |
+
label="Enter your question here",
|
136 |
+
placeholder="Type your message and press Enter...",
|
137 |
scale=4
|
138 |
)
|
139 |
+
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
140 |
+
|
141 |
+
# Right column for controls (smaller)
|
142 |
+
with gr.Column(scale=1):
|
143 |
+
gr.Markdown("### Knowledge Base Controls")
|
144 |
+
build_kb_btn = gr.Button("Create/Update Knowledge Base", variant="primary")
|
145 |
+
check_status_btn = gr.Button("Check Status")
|
146 |
+
kb_status = gr.Textbox(
|
147 |
+
label="Knowledge Base Status",
|
148 |
+
value="Checking status...",
|
149 |
+
interactive=False
|
150 |
+
)
|
151 |
|
152 |
+
gr.Markdown("### Chat Controls")
|
153 |
+
clear_btn = gr.Button("Clear Chat History")
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
+
# Help section
|
156 |
+
with gr.Accordion("ℹ️ How to use", open=False):
|
157 |
+
gr.Markdown("""
|
158 |
+
1. First, click **Create/Update Knowledge Base** button
|
159 |
+
2. Wait for confirmation message
|
160 |
+
3. Enter your question in the text field and press Enter or "Send" button
|
161 |
+
4. Use "Clear Chat History" to start a new conversation
|
162 |
+
""")
|
163 |
+
|
164 |
+
# Event handlers remain the same
|
165 |
+
msg.submit(respond, [msg, chatbot, conversation_id], [chatbot, conversation_id])
|
166 |
+
submit_btn.click(respond, [msg, chatbot, conversation_id], [chatbot, conversation_id])
|
167 |
+
clear_btn.click(clear_history, None, [chatbot, conversation_id])
|
168 |
+
build_kb_btn.click(build_kb, inputs=None, outputs=kb_status)
|
169 |
+
check_status_btn.click(check_kb_status, inputs=None, outputs=kb_status)
|
170 |
|
171 |
if __name__ == "__main__":
|
172 |
# Launch Gradio interface
|