Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import requests
|
|
| 5 |
from datetime import datetime
|
| 6 |
|
| 7 |
# Cấu hình
|
| 8 |
-
LLAMA_SERVER_URL = "http://localhost:
|
| 9 |
|
| 10 |
# Hàm gọi API llama-server
|
| 11 |
def call_llama_server(messages, max_length=50):
|
|
@@ -49,13 +49,13 @@ with gr.Blocks(
|
|
| 49 |
# Cột trái: Danh sách hội thoại
|
| 50 |
with gr.Column(scale=1, min_width=200):
|
| 51 |
gr.Markdown("### Hội thoại")
|
| 52 |
-
conversations = gr.Dropdown(label="Chọn hội thoại", choices=[], value=
|
| 53 |
new_chat_btn = gr.Button("Tạo hội thoại mới", variant="primary")
|
| 54 |
clear_btn = gr.Button("Xóa lịch sử", variant="secondary")
|
| 55 |
|
| 56 |
# Cột phải: Chatbot
|
| 57 |
with gr.Column(scale=3):
|
| 58 |
-
chatbot = gr.Chatbot(label="Cuộc trò chuyện", elem_classes="chatbot")
|
| 59 |
with gr.Row():
|
| 60 |
prompt_input = gr.Textbox(
|
| 61 |
label="Nhập tin nhắn",
|
|
@@ -86,8 +86,7 @@ with gr.Blocks(
|
|
| 86 |
|
| 87 |
return (
|
| 88 |
state,
|
| 89 |
-
|
| 90 |
-
for item in history],
|
| 91 |
""
|
| 92 |
)
|
| 93 |
|
|
@@ -99,11 +98,7 @@ with gr.Blocks(
|
|
| 99 |
if convo_id and convo_id in state["conversations_history"]:
|
| 100 |
state["conversation_id"] = convo_id
|
| 101 |
history = state["conversations_history"][convo_id]
|
| 102 |
-
return (
|
| 103 |
-
state,
|
| 104 |
-
[(item["content"], None) if item["role"] == "user" else (None, item["content"])
|
| 105 |
-
for item in history]
|
| 106 |
-
)
|
| 107 |
return state, []
|
| 108 |
|
| 109 |
def clear_history(state):
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
|
| 7 |
# Cấu hình
|
| 8 |
+
LLAMA_SERVER_URL = "http://localhost:8000/completion" # llama-server chạy trên cổng 8000 nội bộ
|
| 9 |
|
| 10 |
# Hàm gọi API llama-server
|
| 11 |
def call_llama_server(messages, max_length=50):
|
|
|
|
| 49 |
# Cột trái: Danh sách hội thoại
|
| 50 |
with gr.Column(scale=1, min_width=200):
|
| 51 |
gr.Markdown("### Hội thoại")
|
| 52 |
+
conversations = gr.Dropdown(label="Chọn hội thoại", choices=[], value=None, allow_custom_value=True)
|
| 53 |
new_chat_btn = gr.Button("Tạo hội thoại mới", variant="primary")
|
| 54 |
clear_btn = gr.Button("Xóa lịch sử", variant="secondary")
|
| 55 |
|
| 56 |
# Cột phải: Chatbot
|
| 57 |
with gr.Column(scale=3):
|
| 58 |
+
chatbot = gr.Chatbot(label="Cuộc trò chuyện", type="messages", elem_classes="chatbot")
|
| 59 |
with gr.Row():
|
| 60 |
prompt_input = gr.Textbox(
|
| 61 |
label="Nhập tin nhắn",
|
|
|
|
| 86 |
|
| 87 |
return (
|
| 88 |
state,
|
| 89 |
+
format_history(history),
|
|
|
|
| 90 |
""
|
| 91 |
)
|
| 92 |
|
|
|
|
| 98 |
if convo_id and convo_id in state["conversations_history"]:
|
| 99 |
state["conversation_id"] = convo_id
|
| 100 |
history = state["conversations_history"][convo_id]
|
| 101 |
+
return state, format_history(history)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
return state, []
|
| 103 |
|
| 104 |
def clear_history(state):
|