File size: 2,826 Bytes
23b8b85 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# ui_components.py
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)
|