godsastray commited on
Commit
9c03c46
·
verified ·
1 Parent(s): 6dcb856

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -130
app.py CHANGED
@@ -529,142 +529,141 @@ def create_interface():
529
  """)
530
 
531
  # Tab container
532
- tabs = gr.Tabs(selected=0)
533
-
534
- # Tab bắt đầu
535
- with tabs.Tab("🎯 Bắt đầu", id=0) as start_tab:
536
- know_mbti = gr.Radio(
537
- choices=[", tôi đã biết kiểu tính cách MBTI của mình",
538
- "Không, tôi chưa biết kiểu tính cách MBTI của mình"],
539
- label="Bạn đã biết kiểu tính cách MBTI của mình chưa?",
540
- type="index"
541
- )
542
-
543
- # Tab khảo sát MBTI
544
- with tabs.Tab("📝 Khám phá tính cách MBTI", id=1) as test_tab:
545
- gr.Markdown("""### Hãy trả lời các câu hỏi sau để xác định tính cách MBTI của bạn""")
546
 
547
- questions = []
548
- for q in MBTI_QUESTIONS:
549
- questions.append(
550
- gr.Radio(
551
- choices=q["options"],
552
- label=q["question"],
553
- type="index"
 
 
 
 
 
554
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  )
556
 
557
- test_submit = gr.Button("Xác định tính cách MBTI", variant="primary")
558
- mbti_result = gr.Textbox(label="Kết quả tính cách MBTI của bạn", interactive=False)
559
- mbti_description = gr.Markdown(visible=False)
560
-
561
- def on_test_submit(*answers):
562
- mbti_type, description = advisor.calculate_mbti(answers)
563
- return {
564
- mbti_result: mbti_type,
565
- mbti_description: gr.Markdown.update(visible=True, value=description),
566
- tabs: gr.Tabs.update(selected=2) # Chuyển sang tab tư vấn
567
- }
568
-
569
- test_submit.click(
570
- fn=on_test_submit,
571
- inputs=questions,
572
- outputs=[mbti_result, mbti_description, tabs]
573
- )
574
-
575
- # Tab tư vấn nghề nghiệp
576
- with tabs.Tab("💼 vấn nghề nghiệp", id=2) as advice_tab:
577
- mbti_input = gr.Dropdown(
578
- choices=list(MBTI_CAREER_TRAITS.keys()),
579
- label="Kiểu tính cách MBTI của bạn",
580
- info="Chọn kiểu tính cách MBTI đã xác định"
581
- )
582
-
583
- mbti_info = gr.Markdown(visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
 
585
- def update_mbti_info(mbti_type):
586
- if mbti_type:
587
- info = MBTI_CAREER_TRAITS[mbti_type]
588
- description = MBTI_DESCRIPTIONS.get(mbti_type, "")
589
- return gr.Markdown.update(
590
- visible=True,
591
- value=f"""
592
- {description}
593
-
594
- ### 📊 Thông tin chi tiết:
595
-
596
- #### 🎯 Đặc điểm chính:
597
- {info['traits']}
598
-
599
- #### 💪 Điểm mạnh:
600
- {info['strengths']}
601
-
602
- #### 🔄 Điểm cần cải thiện:
603
- {info['weaknesses']}
604
-
605
- #### 👔 Ngành nghề phù hợp:
606
- {info['careers']}
607
- """
608
  )
609
- return gr.Markdown.update(visible=False)
610
-
611
- user_info = gr.Textbox(
612
- label="Chia sẻ thêm về bản thân",
613
- lines=5,
614
- placeholder="Ví dụ: Tôi thích làm việc với số liệu, kỹ năng phân tích tốt..."
615
- )
616
-
617
- get_advice_btn = gr.Button("📋 Nhận tư vấn chi tiết", variant="primary")
618
- advice_output = gr.Markdown(label="Kết quả tư vấn")
619
-
620
- mbti_input.change(
621
- fn=update_mbti_info,
622
- inputs=mbti_input,
623
- outputs=mbti_info
624
- )
625
-
626
- get_advice_btn.click(
627
- fn=advisor.get_career_advice,
628
- inputs=[user_info, mbti_input],
629
- outputs=advice_output
630
- )
631
-
632
- # Tab chat với chuyên gia
633
- with tabs.Tab("💬 Tư vấn 1-1 với Chuyên gia", id=3) as chat_tab:
634
- chatbot = gr.Chatbot(
635
- label="Cuộc trò chuyện",
636
- height=400,
637
- bubble_full_width=False,
638
- avatar_images=(None, "🧑‍💼")
639
- )
640
-
641
- with gr.Row():
642
- msg = gr.Textbox(
643
- label="Nhập câu hỏi của bạn",
644
- placeholder="Ví dụ: Làm thế nào để tôi có thể chuyển sang ngành IT?",
645
- lines=3
646
  )
647
- send_btn = gr.Button("📤 Gửi", variant="primary")
648
-
649
- clear = gr.Button("🗑️ Xóa lịch sử")
650
-
651
- def respond(message, chat_history):
652
- updated_history = advisor.chat_with_advisor(message, chat_history or [])
653
- return "", updated_history
654
-
655
- send_btn.click(
656
- fn=respond,
657
- inputs=[msg, chatbot],
658
- outputs=[msg, chatbot]
659
- )
660
-
661
- msg.submit(
662
- fn=respond,
663
- inputs=[msg, chatbot],
664
- outputs=[msg, chatbot]
665
- )
666
-
667
- clear.click(lambda: None, None, chatbot, queue=False)
668
 
669
  # Xử lý chuyển tab
670
  def handle_know_mbti(choice):
@@ -690,4 +689,4 @@ def main():
690
  )
691
 
692
  if __name__ == "__main__":
693
- main()
 
529
  """)
530
 
531
  # Tab container
532
+ with gr.Tabs() as tabs:
533
+ # Tab bắt đầu
534
+ with gr.TabItem("🎯 Bắt đầu", id=0) as start_tab:
535
+ know_mbti = gr.Radio(
536
+ choices=["Có, tôi đã biết kiểu tính cách MBTI của mình",
537
+ "Không, tôi chưa biết kiểu tính cách MBTI của mình"],
538
+ label="Bạn đã biết kiểu tính cách MBTI của mình chưa?",
539
+ type="index"
540
+ )
 
 
 
 
 
541
 
542
+ # Tab khảo sát MBTI
543
+ with gr.TabItem("📝 Khám phá tính cách MBTI", id=1) as test_tab:
544
+ gr.Markdown("""### Hãy trả lời các câu hỏi sau để xác định tính cách MBTI của bạn""")
545
+
546
+ questions = []
547
+ for q in MBTI_QUESTIONS:
548
+ questions.append(
549
+ gr.Radio(
550
+ choices=q["options"],
551
+ label=q["question"],
552
+ type="index"
553
+ )
554
  )
555
+
556
+ test_submit = gr.Button("Xác định tính cách MBTI", variant="primary")
557
+ mbti_result = gr.Textbox(label="Kết quả tính cách MBTI của bạn", interactive=False)
558
+ mbti_description = gr.Markdown(visible=False)
559
+
560
+ def on_test_submit(*answers):
561
+ mbti_type, description = advisor.calculate_mbti(answers)
562
+ return {
563
+ mbti_result: mbti_type,
564
+ mbti_description: gr.Markdown.update(visible=True, value=description),
565
+ tabs: gr.Tabs.update(selected=2) # Chuyển sang tab tư vấn
566
+ }
567
+
568
+ test_submit.click(
569
+ fn=on_test_submit,
570
+ inputs=questions,
571
+ outputs=[mbti_result, mbti_description, tabs]
572
  )
573
 
574
+ # Tab vấn nghề nghiệp
575
+ with gr.TabItem("💼 vấn nghề nghiệp", id=2) as advice_tab:
576
+ mbti_input = gr.Dropdown(
577
+ choices=list(MBTI_CAREER_TRAITS.keys()),
578
+ label="Kiểu tính cách MBTI của bạn",
579
+ info="Chọn kiểu tính cách MBTI đã xác định"
580
+ )
581
+
582
+ mbti_info = gr.Markdown(visible=False)
583
+
584
+ def update_mbti_info(mbti_type):
585
+ if mbti_type:
586
+ info = MBTI_CAREER_TRAITS[mbti_type]
587
+ description = MBTI_DESCRIPTIONS.get(mbti_type, "")
588
+ return gr.Markdown.update(
589
+ visible=True,
590
+ value=f"""
591
+ {description}
592
+
593
+ ### 📊 Thông tin chi tiết:
594
+
595
+ #### 🎯 Đặc điểm chính:
596
+ {info['traits']}
597
+
598
+ #### 💪 Điểm mạnh:
599
+ {info['strengths']}
600
+
601
+ #### 🔄 Điểm cần cải thiện:
602
+ {info['weaknesses']}
603
+
604
+ #### 👔 Ngành nghề phù hợp:
605
+ {info['careers']}
606
+ """
607
+ )
608
+ return gr.Markdown.update(visible=False)
609
+
610
+ user_info = gr.Textbox(
611
+ label="Chia sẻ thêm về bản thân",
612
+ lines=5,
613
+ placeholder="Ví dụ: Tôi thích làm việc với số liệu, có kỹ năng phân tích tốt..."
614
+ )
615
+
616
+ get_advice_btn = gr.Button("📋 Nhận tư vấn chi tiết", variant="primary")
617
+ advice_output = gr.Markdown(label="Kết quả tư vấn")
618
+
619
+ mbti_input.change(
620
+ fn=update_mbti_info,
621
+ inputs=mbti_input,
622
+ outputs=mbti_info
623
+ )
624
+
625
+ get_advice_btn.click(
626
+ fn=advisor.get_career_advice,
627
+ inputs=[user_info, mbti_input],
628
+ outputs=advice_output
629
+ )
630
 
631
+ # Tab chat với chuyên gia
632
+ with gr.TabItem("💬 Tư vấn 1-1 với Chuyên gia", id=3) as chat_tab:
633
+ chatbot = gr.Chatbot(
634
+ label="Cuộc trò chuyện",
635
+ height=400,
636
+ bubble_full_width=False,
637
+ avatar_images=(None, "🧑‍💼")
638
+ )
639
+
640
+ with gr.Row():
641
+ msg = gr.Textbox(
642
+ label="Nhập câu hỏi của bạn",
643
+ placeholder="Ví dụ: Làm thế nào để tôi có thể chuyển sang ngành IT?",
644
+ lines=3
 
 
 
 
 
 
 
 
 
645
  )
646
+ send_btn = gr.Button("📤 Gửi", variant="primary")
647
+
648
+ clear = gr.Button("🗑️ Xóa lịch sử")
649
+
650
+ def respond(message, chat_history):
651
+ updated_history = advisor.chat_with_advisor(message, chat_history or [])
652
+ return "", updated_history
653
+
654
+ send_btn.click(
655
+ fn=respond,
656
+ inputs=[msg, chatbot],
657
+ outputs=[msg, chatbot]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  )
659
+
660
+ msg.submit(
661
+ fn=respond,
662
+ inputs=[msg, chatbot],
663
+ outputs=[msg, chatbot]
664
+ )
665
+
666
+ clear.click(lambda: None, None, chatbot, queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
667
 
668
  # Xử lý chuyển tab
669
  def handle_know_mbti(choice):
 
689
  )
690
 
691
  if __name__ == "__main__":
692
+ main()