Spaces:
Sleeping
Sleeping
| 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) |