Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -230,7 +230,6 @@ def get_answer(query, queries_listt = None):
|
|
230 |
{"role": "user", "parts": [{"text": augment_prompt(query=query, queries_list=queries_listt)}]}
|
231 |
]
|
232 |
|
233 |
-
queries_list.append(query)
|
234 |
queries = [
|
235 |
{"role": "user", "parts": [{"text": prompt_order(queries_list)}]},
|
236 |
{"role": "user", "parts": [{"text": "Lưu ý: Nếu câu hỏi về môn học, hãy hỏi người dùng về ngành dạy bộ môn đó là ngành nào!"}]}
|
@@ -252,6 +251,8 @@ def get_answer(query, queries_listt = None):
|
|
252 |
def reset_metadata(): #reset metadata button
|
253 |
global metadata
|
254 |
metadata = {}
|
|
|
|
|
255 |
return "{}"
|
256 |
|
257 |
def filter_vector_docs(keyword: str): #check retrived content button
|
@@ -279,31 +280,75 @@ categories = ['Tất cả', 'Đề án', 'Chương trình đào tạo']
|
|
279 |
|
280 |
print("Launching on space... This may take some time...")
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
with gr.Blocks() as demo:
|
283 |
with gr.Row():
|
284 |
-
# Dropdown các trường và danh mục
|
285 |
category1 = gr.Dropdown(choices=institutions, label="Trường", value=None)
|
286 |
category2 = gr.Dropdown(choices=categories, label="Bạn quan tâm tới", value=None)
|
287 |
-
|
288 |
-
#
|
289 |
-
shared_query = gr.Textbox(placeholder="Đặt câu hỏi tại đây", container=False, autoscroll=True, scale=7)
|
290 |
-
chat_interface = gr.ChatInterface(get_answer, textbox=shared_query, type="messages")
|
291 |
-
|
292 |
-
# Phần Metadata: một hàng chứa hộp hiển thị metadata và cột chứa 2 nút (Show Metadata - Reset Metadata)
|
293 |
with gr.Row():
|
294 |
metadata_box = gr.Textbox(label="Metadata", value="{}", interactive=False)
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
reset_meta_button.click(fn=reset_metadata, inputs=[], outputs=metadata_box)
|
302 |
-
|
303 |
-
# Phần lọc các chunk: ô nhập từ khoá và nút "Đọc trích xuất" nằm cùng hàng, kết quả hiển thị bên dưới
|
304 |
with gr.Row():
|
305 |
-
filter_prompt = gr.Textbox(label="Nhập từ khoá", placeholder="Nhập từ khoá", interactive=True)
|
306 |
-
filter_button = gr.Button("
|
307 |
filter_output = gr.Textbox(label="Content", interactive=False)
|
308 |
filter_button.click(fn=filter_vector_docs, inputs=filter_prompt, outputs=filter_output)
|
309 |
|
|
|
230 |
{"role": "user", "parts": [{"text": augment_prompt(query=query, queries_list=queries_listt)}]}
|
231 |
]
|
232 |
|
|
|
233 |
queries = [
|
234 |
{"role": "user", "parts": [{"text": prompt_order(queries_list)}]},
|
235 |
{"role": "user", "parts": [{"text": "Lưu ý: Nếu câu hỏi về môn học, hãy hỏi người dùng về ngành dạy bộ môn đó là ngành nào!"}]}
|
|
|
251 |
def reset_metadata(): #reset metadata button
|
252 |
global metadata
|
253 |
metadata = {}
|
254 |
+
global queries_list
|
255 |
+
queries_list = {}
|
256 |
return "{}"
|
257 |
|
258 |
def filter_vector_docs(keyword: str): #check retrived content button
|
|
|
280 |
|
281 |
print("Launching on space... This may take some time...")
|
282 |
|
283 |
+
# with gr.Blocks() as demo:
|
284 |
+
# with gr.Row():
|
285 |
+
# # Dropdown các trường và danh mục
|
286 |
+
# category1 = gr.Dropdown(choices=institutions, label="Trường", value=None)
|
287 |
+
# category2 = gr.Dropdown(choices=categories, label="Bạn quan tâm tới", value=None)
|
288 |
+
|
289 |
+
# # Chat Interface sử dụng ô nhập chung và callback get_answer
|
290 |
+
# shared_query = gr.Textbox(placeholder="Đặt câu hỏi tại đây", container=False, autoscroll=True, scale=7)
|
291 |
+
# chat_interface = gr.ChatInterface(get_answer, textbox=shared_query, type="messages")
|
292 |
+
|
293 |
+
# # Phần Metadata: một hàng chứa hộp hiển thị metadata và cột chứa 2 nút (Show Metadata - Reset Metadata)
|
294 |
+
# with gr.Row():
|
295 |
+
# metadata_box = gr.Textbox(label="Metadata", value="{}", interactive=False)
|
296 |
+
# with gr.Column():
|
297 |
+
# show_meta_button = gr.Button("Show Metadata")
|
298 |
+
# reset_meta_button = gr.Button("Hỏi cái khác")
|
299 |
+
|
300 |
+
# # Kết nối các nút với các hàm tương ứng
|
301 |
+
# show_meta_button.click(fn=get_metadata, inputs=[], outputs=metadata_box)
|
302 |
+
# reset_meta_button.click(fn=reset_metadata, inputs=[], outputs=metadata_box)
|
303 |
+
|
304 |
+
# # Phần lọc các chunk: ô nhập từ khoá và nút "Đọc trích xuất" nằm cùng hàng, kết quả hiển thị bên dưới
|
305 |
+
# with gr.Row():
|
306 |
+
# filter_prompt = gr.Textbox(label="Nhập từ khoá", placeholder="Nhập từ khoá", interactive=True)
|
307 |
+
# filter_button = gr.Button("Đọc trích xuất")
|
308 |
+
# filter_output = gr.Textbox(label="Content", interactive=False)
|
309 |
+
# filter_button.click(fn=filter_vector_docs, inputs=filter_prompt, outputs=filter_output)
|
310 |
+
|
311 |
with gr.Blocks() as demo:
|
312 |
with gr.Row():
|
|
|
313 |
category1 = gr.Dropdown(choices=institutions, label="Trường", value=None)
|
314 |
category2 = gr.Dropdown(choices=categories, label="Bạn quan tâm tới", value=None)
|
315 |
+
|
316 |
+
# Create the metadata display box at the top for better visibility
|
|
|
|
|
|
|
|
|
317 |
with gr.Row():
|
318 |
metadata_box = gr.Textbox(label="Metadata", value="{}", interactive=False)
|
319 |
+
reset_meta_button = gr.Button("Reset Metadata", scale=0.5)
|
320 |
+
|
321 |
+
# Use a custom submit function to handle both answer generation and metadata updating
|
322 |
+
shared_query = gr.Textbox(placeholder="Đặt câu hỏi tại đây", container=False, autoscroll=True, scale=7)
|
323 |
+
|
324 |
+
# Modified chat interface with custom submit function
|
325 |
+
chatbot = gr.Chatbot()
|
326 |
+
|
327 |
+
def submit_query(message, chat_history):
|
328 |
+
response, metadata_str = get_answer(message)
|
329 |
+
chat_history.append((message, response))
|
330 |
+
return "", chat_history, metadata_str
|
331 |
+
|
332 |
+
submit_btn = gr.Button("Gửi")
|
333 |
+
submit_btn.click(
|
334 |
+
fn=submit_query,
|
335 |
+
inputs=[shared_query, chatbot],
|
336 |
+
outputs=[shared_query, chatbot, metadata_box]
|
337 |
+
)
|
338 |
+
|
339 |
+
# Also handle Enter key press in the text box
|
340 |
+
shared_query.submit(
|
341 |
+
fn=submit_query,
|
342 |
+
inputs=[shared_query, chatbot],
|
343 |
+
outputs=[shared_query, chatbot, metadata_box]
|
344 |
+
)
|
345 |
+
|
346 |
+
# Connect reset button to reset function
|
347 |
reset_meta_button.click(fn=reset_metadata, inputs=[], outputs=metadata_box)
|
348 |
+
|
|
|
349 |
with gr.Row():
|
350 |
+
filter_prompt = gr.Textbox(label="Nhập từ khoá", placeholder="Nhập từ khoá để lọc (để trống để hiển thị tất cả)", interactive=True)
|
351 |
+
filter_button = gr.Button("Tìm trích xuất")
|
352 |
filter_output = gr.Textbox(label="Content", interactive=False)
|
353 |
filter_button.click(fn=filter_vector_docs, inputs=filter_prompt, outputs=filter_output)
|
354 |
|