File size: 2,025 Bytes
cb3d0a6
 
2f57b59
cb3d0a6
7cc305d
 
 
 
 
 
cb3d0a6
 
 
 
 
 
7cc305d
cb3d0a6
 
 
4d31b24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7cc305d
 
cb3d0a6
 
 
 
 
 
 
 
 
 
7d3bd77
cb3d0a6
 
 
 
7d3bd77
7cc305d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import pandas as pd
import analyze_embedding 

custom_css = """
.gradio-container {
    max-width: 95% !important; 
}
"""

default_base_text = """Tôi rất thích nghiên cứu về Trí tuệ nhân tạo.
I love studying Artificial Intelligence.
Con mèo đang ngủ trên ghế sofa.
The cat is taking a nap on the couch.
Công thức làm bánh pizza ngon nhất thế giới."""

with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
    gr.Markdown("### Interactive Demo: Đại chiến 3 Mô hình (Dữ liệu nền động)")
    gr.Markdown("Bạn có thể thêm, sửa, xóa dữ liệu nền (Knowledge Base) tùy ý. Mỗi câu nằm trên một dòng.")
    
    with gr.Column():
        with gr.Row():
            with gr.Column(scale=1):
                base_input = gr.Textbox(
                    label="Dữ liệu nền (Knowledge Base)", 
                    value=default_base_text, 
                    lines=7, 
                    info="Ấn Enter để xuống dòng thêm câu mới."
                )
                
            # Cột 2: Ô nhập câu hỏi của user (chiếm 50% màn hình)
            with gr.Column(scale=1):
                user_input = gr.Textbox(
                    label="Nhập câu của bạn:", 
                    placeholder="VD: Mèo là loài động vật rất dễ thương...", 
                    lines=2
                )
        
        analyze_btn = gr.Button("Phân tích cả 3 Models", variant="primary")
        
    with gr.Row():
        plot_sbert = gr.Plot(label="Vietnamese SBERT")
        plot_e5 = gr.Plot(label="Microsoft E5")
        plot_bge = gr.Plot(label="BAAI BGE-M3")
        
    gr.Markdown("### Bảng so sánh Độ tương đồng Cosine")
    table_output = gr.Dataframe()

    analyze_btn.click(
        fn=analyze_embedding.process_embedding_analysis,
        inputs=[user_input, base_input],
        outputs=[plot_sbert, plot_e5, plot_bge, table_output] 
    )


demo.launch(share=True)