| | |
| | import streamlit as st |
| | from typing import List, Dict |
| | from config import Config |
| | from chat_state import ChatState |
| | from chat_manager import ChatManager |
| | from chat_service import ChatService |
| |
|
| |
|
| | class UIComponents: |
| | @staticmethod |
| | def setup_page(config: Config) -> None: |
| | st.set_page_config(**config.PAGE_CONFIG) |
| | st.markdown(config.STYLES, unsafe_allow_html=True) |
| |
|
| | @staticmethod |
| | def render_header() -> None: |
| | st.markdown( |
| | '<h1 style="color: black;">المرشد التعليمي الذكي 🤖</h1>', |
| | unsafe_allow_html=True, |
| | ) |
| |
|
| | @staticmethod |
| | def render_footer() -> None: |
| | st.markdown( |
| | """ |
| | <div class="footer"> |
| | .هذا روبوت تعليمي ذكي وقد تختلف إجاباته في كل مرة. يرجى استخدامه كدليل أولي فقط |
| | </div> |
| | """, |
| | unsafe_allow_html=True, |
| | ) |
| |
|
| | @staticmethod |
| | def render_sidebar( |
| | chat_state: ChatState, chat_manager: ChatManager, chat_service: ChatService |
| | ) -> None: |
| | with st.sidebar: |
| | st.title("إدارة المحادثات") |
| |
|
| | if st.button("محادثة جديدة 🆕"): |
| | chat_state.temp_chat = chat_manager.create_new_chat() |
| | chat_state.current_chat_id = None |
| |
|
| | chat_ids = list(chat_state.chat_history.keys()) |
| | if chat_ids: |
| | chat_options = { |
| | id: chat_service.get_chat_preview(chat_state.chat_history[id]) |
| | for id in chat_ids |
| | } |
| | chat_options["new"] = "محادثة جديدة 🆕" |
| |
|
| | selected_chat = st.selectbox( |
| | "اختر محادثة 📚", |
| | options=list(chat_options.keys()), |
| | format_func=lambda x: chat_options[x], |
| | index=( |
| | len(chat_options) - 1 |
| | if chat_state.current_chat_id is None |
| | else chat_ids.index(chat_state.current_chat_id) |
| | ), |
| | ) |
| |
|
| | if selected_chat == "new": |
| | chat_state.temp_chat = chat_manager.create_new_chat() |
| | chat_state.current_chat_id = None |
| | elif selected_chat != chat_state.current_chat_id: |
| | chat_state.current_chat_id = selected_chat |
| | chat_state.temp_chat = None |
| |
|
| | if chat_state.current_chat_id: |
| | if st.button("حذف المحادثة الحالية 🗑️"): |
| | chat_state.delete_chat_id = chat_state.current_chat_id |
| |
|
| | if chat_state.delete_chat_id: |
| | chat_manager.delete_chat(chat_state.delete_chat_id, chat_state) |
| |
|