Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| import call_api | |
| chat = gr.ChatInterface( | |
| call_api.call_deepseek, #chat | |
| title="Trợ lý Học Tập AI", | |
| description="Nhập câu hỏi của bạn về Toán, Lý, Hóa, Văn… và nhận giải đáp chi tiết ngay lập tức!", | |
| additional_inputs=[ | |
| gr.Textbox("Bạn là một chatbot tiếng Việt thân thiện.", label="System message"), | |
| gr.Slider(1, 2000, value=500, step=1, label="Max token (Độ dài câu trả lời)"), | |
| gr.Slider(0.0, 2.0, value=0.7, step=0.2, label="Temperature (Độ sáng tạo): Lập trình/Toán 0.1 | Làm sạch/Phân tích dữ liệu 1.0 | Trò chuyện 1.3 | Dịch thuật 1.3 | Viết sáng tạo/Thơ ca 1.5"), | |
| gr.Slider(0.0, 1.0, value=0.9, step=0.1, label="Top-p/nucleus sampling (Đạ đa dạng từ ngữ): p thấp→ an toàn, p cao→ sáng tạo."), | |
| # gr.Image(label="Attach an image (optional)"), # báo lỗi | |
| # gr.File(label="Upload a file (optional)"), # báo lỗi | |
| ], | |
| examples=[ | |
| # Mỗi item: [message, system_message, max_tokens, temperature, top_p] | |
| ["tích phân của x^2 từ 0 đến 2 là gì?, vui lòng lập luận từng bước, trình bày bằng kí tự cơ bản", "bạn là giáo viên toán học", 1000, 0.1, 0.9], | |
| ], | |
| ) | |
| # Chạy app | |
| if __name__ == "__main__": | |
| chat.launch(show_error=True) | |
| """ | |
| """ | |
| # with gr.Blocks() as demo: # Bắt đầu Blocks | |
| # # Thành phần hiển thị lịch sử chat | |
| # chatbot = gr.Chatbot(type="messages") # hỗ trợ subset Markdown:contentReference[oaicite:3]{index=3} | |
| # # Thành phần Markdown để render kết quả đã format (Markdown + LaTeX) | |
| # markdown = gr.Markdown( | |
| # latex_delimiters=[{"left": "$$", "right": "$$", "display": True}] | |
| # ) # cho phép render LaTeX:contentReference[oaicite:4]{index=4} | |
| # # Các input controls | |
| # with gr.Row(): | |
| # txt = gr.Textbox(label="Nhập câu hỏi") | |
| # sys_msg = gr.Textbox(value="Bạn là một chatbot tiếng Việt thân thiện.", label="System message") | |
| # with gr.Row(): | |
| # max_t = gr.Slider(1, 2048, value=500, step=1, label="Max new tokens") | |
| # temp = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature") | |
| # top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p") | |
| # # Sự kiện submit | |
| # txt.submit( | |
| # call_deepseek_new, | |
| # inputs=[txt, chatbot], | |
| # outputs=[chatbot, markdown], | |
| # ) | |