Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +92 -133
src/streamlit_app.py
CHANGED
|
@@ -3,163 +3,122 @@ from openai import OpenAI
|
|
| 3 |
import time
|
| 4 |
import json
|
| 5 |
|
| 6 |
-
# إعداد الصفحة
|
| 7 |
st.set_page_config(page_title="Genisi - Chatbot", page_icon="🤖", layout="wide")
|
| 8 |
|
| 9 |
-
# ت
|
| 10 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
<style>
|
| 12 |
-
/* تنسيق عام - لون
|
| 13 |
-
.stApp
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
/*
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
}
|
| 22 |
|
| 23 |
-
/*
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
}
|
| 27 |
|
| 28 |
-
/*
|
| 29 |
-
.stButton button {
|
| 30 |
-
background-color:
|
| 31 |
-
color:
|
| 32 |
-
border: 1px solid
|
| 33 |
border-radius: 5px;
|
| 34 |
width: 100%;
|
| 35 |
text-align: right;
|
| 36 |
-
|
| 37 |
-
}
|
| 38 |
|
| 39 |
-
.stButton button:hover {
|
| 40 |
-
background-color:
|
| 41 |
-
border-color:
|
| 42 |
-
}
|
| 43 |
|
| 44 |
-
/*
|
| 45 |
-
.chat-title {
|
| 46 |
font-size: 24px;
|
| 47 |
font-weight: 600;
|
| 48 |
-
color:
|
| 49 |
margin-bottom: 20px;
|
| 50 |
padding: 10px 20px;
|
| 51 |
-
border-bottom: 1px solid
|
| 52 |
text-align: center;
|
| 53 |
-
}
|
| 54 |
|
| 55 |
-
/*
|
| 56 |
-
.
|
| 57 |
-
color: #E0E0E0; /* نفس لون النص العادي */
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
/* تنسيق معلومات الم developer - نفس اللون */
|
| 61 |
-
.developer-info {
|
| 62 |
position: fixed;
|
| 63 |
bottom: 0;
|
| 64 |
left: 0;
|
| 65 |
right: 0;
|
| 66 |
text-align: center;
|
| 67 |
padding: 10px;
|
| 68 |
-
background-color:
|
| 69 |
-
color:
|
| 70 |
font-size: 12px;
|
| 71 |
-
border-top: 1px solid
|
| 72 |
z-index: 999;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
/* تنسيق رسائل الشات - لون موحد */
|
| 76 |
-
.stChatMessage {
|
| 77 |
-
background-color: #1E1E1E;
|
| 78 |
-
border: none;
|
| 79 |
-
}
|
| 80 |
|
| 81 |
-
/*
|
| 82 |
-
|
| 83 |
-
background-color:
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
/* تنسيق رسالة المساعد */
|
| 87 |
-
div[data-testid="stChatMessage"]:has(div[data-testid="chatAvatarIcon-assistant"]) {
|
| 88 |
-
background-color: #1E1E1E;
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
/* تنسيق مربع الإدخال */
|
| 92 |
-
.stChatInputContainer {
|
| 93 |
-
background-color: #2D2D2D;
|
| 94 |
-
border: 1px solid #404040;
|
| 95 |
border-radius: 5px;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
.stChatInputContainer input {
|
| 99 |
-
background-color: #2D2D2D;
|
| 100 |
-
color: #E0E0E0;
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
/* تنسيق جميع النصوص - لون موحد */
|
| 104 |
-
p, h1, h2, h3, h4, h5, h6, label, span {
|
| 105 |
-
color: #E0E0E0 !important;
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
/* تنسيق الروابط - بدون لون مميز */
|
| 109 |
-
a {
|
| 110 |
-
color: #B0B0B0 !important;
|
| 111 |
-
text-decoration: underline;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
a:hover {
|
| 115 |
-
color: #D0D0D0 !important;
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
/* تنسيق الأفاتار - ألوان رمادية */
|
| 119 |
-
div[data-testid="chatAvatarIcon-user"] {
|
| 120 |
-
background-color: #404040 !important;
|
| 121 |
-
color: #E0E0E0 !important;
|
| 122 |
-
}
|
| 123 |
|
| 124 |
-
|
| 125 |
-
background-color:
|
| 126 |
-
color:
|
| 127 |
-
}
|
| 128 |
|
| 129 |
-
/* إزالة
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
| 137 |
|
| 138 |
-
/*
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
border: 1px solid
|
| 142 |
-
|
| 143 |
-
}
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
color:
|
| 148 |
-
|
|
|
|
| 149 |
</style>
|
| 150 |
-
|
| 151 |
-
<script>
|
| 152 |
-
// دالة لحفظ المحادثات في localStorage
|
| 153 |
-
function saveConversations(conversations) {
|
| 154 |
-
localStorage.setItem('genisi_conversations', JSON.stringify(conversations));
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
// دالة لتحميل المحادثات من localStorage
|
| 158 |
-
function loadConversations() {
|
| 159 |
-
const saved = localStorage.getItem('genisi_conversations');
|
| 160 |
-
return saved ? JSON.parse(saved) : [];
|
| 161 |
-
}
|
| 162 |
-
</script>
|
| 163 |
""", unsafe_allow_html=True)
|
| 164 |
|
| 165 |
# مفتاح API
|
|
@@ -196,10 +155,10 @@ if (conversations) {
|
|
| 196 |
|
| 197 |
# الشريط الجانبي - قائمة المحادثات
|
| 198 |
with st.sidebar:
|
| 199 |
-
st.markdown('<p style="color:
|
| 200 |
-
st.markdown('<p style="color:
|
| 201 |
|
| 202 |
-
# زر محادثة جديدة
|
| 203 |
if st.button("➕ محادثة جديدة", use_container_width=True):
|
| 204 |
new_chat = {
|
| 205 |
"id": str(time.time()),
|
|
@@ -235,7 +194,7 @@ with st.sidebar:
|
|
| 235 |
# تاريخ المحادثة
|
| 236 |
created_at = conv.get("created_at", "")
|
| 237 |
|
| 238 |
-
# تنسيق المحادثة
|
| 239 |
col1, col2, col3 = st.columns([5, 1, 1])
|
| 240 |
|
| 241 |
with col1:
|
|
@@ -272,14 +231,14 @@ with st.sidebar:
|
|
| 272 |
|
| 273 |
st.rerun()
|
| 274 |
|
| 275 |
-
# عرض تاريخ المحادثة
|
| 276 |
if created_at:
|
| 277 |
-
st.markdown(f'<p style="color:
|
| 278 |
else:
|
| 279 |
-
st.markdown('<p style="color:
|
| 280 |
|
| 281 |
# المحتوى الرئيسي
|
| 282 |
-
st.markdown('<div class="chat-title">🤖
|
| 283 |
|
| 284 |
# عرض المحادثة الحالية
|
| 285 |
for msg in st.session_state.messages:
|
|
@@ -362,4 +321,4 @@ if prompt := st.chat_input("اكتب سؤالك هنا..."):
|
|
| 362 |
st.error(f"حدث خطأ: {str(e)}")
|
| 363 |
|
| 364 |
# معلومات المطور
|
| 365 |
-
st.markdown('<div class="developer-info">تم التطوير بواسطة AnesNT
|
|
|
|
| 3 |
import time
|
| 4 |
import json
|
| 5 |
|
| 6 |
+
# إعداد الصفحة
|
| 7 |
st.set_page_config(page_title="Genisi - Chatbot", page_icon="🤖", layout="wide")
|
| 8 |
|
| 9 |
+
# اختيار الوضع (فاتح/داكن) من الشريط الجانبي
|
| 10 |
+
with st.sidebar:
|
| 11 |
+
theme = st.radio("🎨 الوضع", ["فاتح", "داكن"], index=0)
|
| 12 |
+
|
| 13 |
+
# تطبيق الأنماط حسب الوضع المختار
|
| 14 |
+
if theme == "فاتح":
|
| 15 |
+
bg_color = "#FFFFFF" # أبيض كامل للخلفية
|
| 16 |
+
text_color = "#000000" # أسود كامل للنصوص
|
| 17 |
+
border_color = "#E0E0E0" # رمادي فاتح جداً للحدود فقط
|
| 18 |
+
secondary_bg = "#FFFFFF" # نفس الأبيض
|
| 19 |
+
else: # داكن
|
| 20 |
+
bg_color = "#000000" # أسود كامل للخلفية
|
| 21 |
+
text_color = "#FFFFFF" # أبيض كامل للنصوص
|
| 22 |
+
border_color = "#333333" # رمادي غامق جداً للحدود فقط
|
| 23 |
+
secondary_bg = "#000000" # نفس الأسود
|
| 24 |
+
|
| 25 |
+
# CSS بسيط جداً - لون واحد فقط
|
| 26 |
+
st.markdown(f"""
|
| 27 |
<style>
|
| 28 |
+
/* تنسيق عام - لون واحد فقط */
|
| 29 |
+
.stApp, section[data-testid="stSidebar"], .stMarkdown,
|
| 30 |
+
div[data-testid="stVerticalBlock"], div[data-testid="stChatMessage"] {{
|
| 31 |
+
background-color: {bg_color} !important;
|
| 32 |
+
}}
|
| 33 |
|
| 34 |
+
/* جميع النصوص بلون واحد */
|
| 35 |
+
p, h1, h2, h3, h4, h5, h6, label, span, div, .stChatMessage {{
|
| 36 |
+
color: {text_color} !important;
|
| 37 |
+
}}
|
|
|
|
| 38 |
|
| 39 |
+
/* حدود بسيطة جداً للعناصر */
|
| 40 |
+
section[data-testid="stSidebar"] {{
|
| 41 |
+
border-left: 1px solid {border_color};
|
| 42 |
+
}}
|
| 43 |
|
| 44 |
+
/* الأزرار - بدون خلفية مميزة */
|
| 45 |
+
.stButton button {{
|
| 46 |
+
background-color: {bg_color};
|
| 47 |
+
color: {text_color};
|
| 48 |
+
border: 1px solid {border_color};
|
| 49 |
border-radius: 5px;
|
| 50 |
width: 100%;
|
| 51 |
text-align: right;
|
| 52 |
+
}}
|
|
|
|
| 53 |
|
| 54 |
+
.stButton button:hover {{
|
| 55 |
+
background-color: {bg_color};
|
| 56 |
+
border-color: {text_color};
|
| 57 |
+
}}
|
| 58 |
|
| 59 |
+
/* عنوان الشات */
|
| 60 |
+
.chat-title {{
|
| 61 |
font-size: 24px;
|
| 62 |
font-weight: 600;
|
| 63 |
+
color: {text_color};
|
| 64 |
margin-bottom: 20px;
|
| 65 |
padding: 10px 20px;
|
| 66 |
+
border-bottom: 1px solid {border_color};
|
| 67 |
text-align: center;
|
| 68 |
+
}}
|
| 69 |
|
| 70 |
+
/* معلومات المطور */
|
| 71 |
+
.developer-info {{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
position: fixed;
|
| 73 |
bottom: 0;
|
| 74 |
left: 0;
|
| 75 |
right: 0;
|
| 76 |
text-align: center;
|
| 77 |
padding: 10px;
|
| 78 |
+
background-color: {bg_color};
|
| 79 |
+
color: {text_color};
|
| 80 |
font-size: 12px;
|
| 81 |
+
border-top: 1px solid {border_color};
|
| 82 |
z-index: 999;
|
| 83 |
+
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
/* مربع الإدخال */
|
| 86 |
+
.stChatInputContainer {{
|
| 87 |
+
background-color: {bg_color};
|
| 88 |
+
border: 1px solid {border_color};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
border-radius: 5px;
|
| 90 |
+
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
.stChatInputContainer input {{
|
| 93 |
+
background-color: {bg_color};
|
| 94 |
+
color: {text_color};
|
| 95 |
+
}}
|
| 96 |
|
| 97 |
+
/* إزالة أي ألوان مميزة من الأفاتار */
|
| 98 |
+
div[data-testid="chatAvatarIcon-user"],
|
| 99 |
+
div[data-testid="chatAvatarIcon-assistant"] {{
|
| 100 |
+
background-color: {border_color} !important;
|
| 101 |
+
color: {text_color} !important;
|
| 102 |
+
border: 1px solid {border_color};
|
| 103 |
+
}}
|
| 104 |
|
| 105 |
+
/* خط فاصل بسيط */
|
| 106 |
+
hr {{
|
| 107 |
+
border-color: {border_color} !important;
|
| 108 |
+
}}
|
| 109 |
|
| 110 |
+
/* رسائل الشات - بدون تمييز */
|
| 111 |
+
div[data-testid="stChatMessage"] {{
|
| 112 |
+
border: none;
|
| 113 |
+
border-bottom: 1px solid {border_color};
|
| 114 |
+
}}
|
|
|
|
| 115 |
|
| 116 |
+
/* إزالة أي ألوان من الروابط */
|
| 117 |
+
a {{
|
| 118 |
+
color: {text_color} !important;
|
| 119 |
+
text-decoration: underline;
|
| 120 |
+
}}
|
| 121 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
""", unsafe_allow_html=True)
|
| 123 |
|
| 124 |
# مفتاح API
|
|
|
|
| 155 |
|
| 156 |
# الشريط الجانبي - قائمة المحادثات
|
| 157 |
with st.sidebar:
|
| 158 |
+
st.markdown(f'<p style="color: {text_color}; font-size: 20px; font-weight: bold; text-align: center; padding: 20px 20px 5px;">🤖 Genisi</p>', unsafe_allow_html=True)
|
| 159 |
+
st.markdown(f'<p style="color: {text_color}; text-align: center; margin-top: -5px;">by AnesNT</p>', unsafe_allow_html=True)
|
| 160 |
|
| 161 |
+
# زر محادثة جديدة
|
| 162 |
if st.button("➕ محادثة جديدة", use_container_width=True):
|
| 163 |
new_chat = {
|
| 164 |
"id": str(time.time()),
|
|
|
|
| 194 |
# تاريخ المحادثة
|
| 195 |
created_at = conv.get("created_at", "")
|
| 196 |
|
| 197 |
+
# تنسيق المحادثة
|
| 198 |
col1, col2, col3 = st.columns([5, 1, 1])
|
| 199 |
|
| 200 |
with col1:
|
|
|
|
| 231 |
|
| 232 |
st.rerun()
|
| 233 |
|
| 234 |
+
# عرض تاريخ المحادثة
|
| 235 |
if created_at:
|
| 236 |
+
st.markdown(f'<p style="color: {text_color}; font-size: 11px; margin: -5px 0 10px 25px;">{created_at}</p>', unsafe_allow_html=True)
|
| 237 |
else:
|
| 238 |
+
st.markdown(f'<p style="color: {text_color}; text-align: center; padding: 20px;">لا توجد محادثات سابقة</p>', unsafe_allow_html=True)
|
| 239 |
|
| 240 |
# المحتوى الرئيسي
|
| 241 |
+
st.markdown(f'<div class="chat-title">🤖 Genisi - AI Assistant by AnesNT</div>', unsafe_allow_html=True)
|
| 242 |
|
| 243 |
# عرض المحادثة الحالية
|
| 244 |
for msg in st.session_state.messages:
|
|
|
|
| 321 |
st.error(f"حدث خطأ: {str(e)}")
|
| 322 |
|
| 323 |
# معلومات المطور
|
| 324 |
+
st.markdown(f'<div class="developer-info">تم التطوير بواسطة AnesNT</div>', unsafe_allow_html=True)
|