Update index.html
Browse files- index.html +64 -39
index.html
CHANGED
|
@@ -14,7 +14,6 @@
|
|
| 14 |
height: 100vh;
|
| 15 |
background-color: #f0f0f0;
|
| 16 |
}
|
| 17 |
-
|
| 18 |
.sidebar {
|
| 19 |
width: 260px;
|
| 20 |
background-color: #ffffff;
|
|
@@ -24,7 +23,6 @@
|
|
| 24 |
border-left: 1px solid #e0e0e0;
|
| 25 |
overflow-y: auto;
|
| 26 |
}
|
| 27 |
-
|
| 28 |
.logo {
|
| 29 |
font-size: 28px;
|
| 30 |
font-weight: bold;
|
|
@@ -32,25 +30,21 @@
|
|
| 32 |
text-align: center;
|
| 33 |
color: #333;
|
| 34 |
}
|
| 35 |
-
|
| 36 |
.menu-item {
|
| 37 |
padding: 10px;
|
| 38 |
margin-bottom: 5px;
|
| 39 |
cursor: pointer;
|
| 40 |
border-radius: 5px;
|
| 41 |
}
|
| 42 |
-
|
| 43 |
.menu-item:hover {
|
| 44 |
background-color: #f0f0f0;
|
| 45 |
}
|
| 46 |
-
|
| 47 |
.main-content {
|
| 48 |
flex-grow: 1;
|
| 49 |
display: flex;
|
| 50 |
flex-direction: column;
|
| 51 |
padding: 20px;
|
| 52 |
}
|
| 53 |
-
|
| 54 |
.header {
|
| 55 |
display: flex;
|
| 56 |
justify-content: space-between;
|
|
@@ -61,13 +55,11 @@
|
|
| 61 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 62 |
margin-bottom: 20px;
|
| 63 |
}
|
| 64 |
-
|
| 65 |
.header-title {
|
| 66 |
font-size: 24px;
|
| 67 |
font-weight: bold;
|
| 68 |
color: #333;
|
| 69 |
}
|
| 70 |
-
|
| 71 |
.chat-container {
|
| 72 |
flex-grow: 1;
|
| 73 |
display: flex;
|
|
@@ -77,14 +69,12 @@
|
|
| 77 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 78 |
overflow: hidden;
|
| 79 |
}
|
| 80 |
-
|
| 81 |
.messages {
|
| 82 |
flex: 1;
|
| 83 |
overflow-y: auto;
|
| 84 |
padding: 15px;
|
| 85 |
background-color: #fafafa;
|
| 86 |
}
|
| 87 |
-
|
| 88 |
.message {
|
| 89 |
padding: 12px;
|
| 90 |
margin: 8px 0;
|
|
@@ -93,26 +83,22 @@
|
|
| 93 |
max-width: 70%;
|
| 94 |
word-break: break-word;
|
| 95 |
}
|
| 96 |
-
|
| 97 |
.user-message {
|
| 98 |
text-align: left;
|
| 99 |
background-color: #e0e0e0;
|
| 100 |
margin-right: auto;
|
| 101 |
}
|
| 102 |
-
|
| 103 |
.bot-message {
|
| 104 |
text-align: right;
|
| 105 |
background-color: #f5f5f5;
|
| 106 |
margin-left: auto;
|
| 107 |
}
|
| 108 |
-
|
| 109 |
.input-container {
|
| 110 |
display: flex;
|
| 111 |
padding: 12px;
|
| 112 |
background-color: #ffffff;
|
| 113 |
border-top: 1px solid #e0e0e0;
|
| 114 |
}
|
| 115 |
-
|
| 116 |
.input-container input {
|
| 117 |
flex: 1;
|
| 118 |
padding: 12px;
|
|
@@ -121,7 +107,6 @@
|
|
| 121 |
margin-left: 10px;
|
| 122 |
font-size: 16px;
|
| 123 |
}
|
| 124 |
-
|
| 125 |
.input-container button {
|
| 126 |
padding: 12px 24px;
|
| 127 |
border-radius: 12px;
|
|
@@ -131,17 +116,14 @@
|
|
| 131 |
cursor: pointer;
|
| 132 |
font-size: 16px;
|
| 133 |
}
|
| 134 |
-
|
| 135 |
.input-container button:hover {
|
| 136 |
background-color: #666;
|
| 137 |
}
|
| 138 |
-
|
| 139 |
.quick-actions {
|
| 140 |
display: flex;
|
| 141 |
justify-content: center;
|
| 142 |
margin-top: 20px;
|
| 143 |
}
|
| 144 |
-
|
| 145 |
.action-button {
|
| 146 |
background-color: #f0f0f0;
|
| 147 |
color: #333;
|
|
@@ -151,7 +133,6 @@
|
|
| 151 |
border-radius: 5px;
|
| 152 |
cursor: pointer;
|
| 153 |
}
|
| 154 |
-
|
| 155 |
footer {
|
| 156 |
text-align: center;
|
| 157 |
padding: 15px;
|
|
@@ -160,12 +141,19 @@
|
|
| 160 |
margin-top: 20px;
|
| 161 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 162 |
}
|
| 163 |
-
|
| 164 |
@media (max-width: 768px) {
|
| 165 |
.sidebar {
|
| 166 |
display: none;
|
| 167 |
}
|
| 168 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
</style>
|
| 170 |
</head>
|
| 171 |
<body>
|
|
@@ -189,18 +177,18 @@
|
|
| 189 |
<div class="messages" id="messages">
|
| 190 |
<!-- Messages will be displayed here -->
|
| 191 |
</div>
|
| 192 |
-
|
| 193 |
<div class="input-container">
|
| 194 |
-
<input type="text" id="message-input" placeholder="اكتب رسالتك...">
|
| 195 |
<button onclick="sendMessage()">إرسال</button>
|
| 196 |
</div>
|
| 197 |
</div>
|
| 198 |
|
| 199 |
<div class="quick-actions">
|
| 200 |
-
<button class="action-button">إنشاء صورة</button>
|
| 201 |
-
<button class="action-button">شرح موضوع</button>
|
| 202 |
-
<button class="action-button">شكر المقابل</button>
|
| 203 |
-
<button class="action-button">حقيقة مثيرة</button>
|
| 204 |
</div>
|
| 205 |
|
| 206 |
<footer>
|
|
@@ -209,21 +197,47 @@
|
|
| 209 |
</div>
|
| 210 |
|
| 211 |
<script>
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
var input = document.getElementById('message-input');
|
| 214 |
var message = input.value.trim();
|
| 215 |
-
|
| 216 |
if (message !== '') {
|
|
|
|
|
|
|
|
|
|
| 217 |
appendMessage('user-message', message);
|
| 218 |
-
|
| 219 |
-
// هنا يمكنك إضافة الكود الخاص بإرسال الرسالة إلى الخادم
|
| 220 |
-
// وتلقي الرد، ولكن في هذا المثال سنقوم فقط بمحاكاة الرد
|
| 221 |
-
|
| 222 |
-
setTimeout(() => {
|
| 223 |
-
appendMessage('bot-message', 'شكرًا لرسالتك. كيف يمكنني مساعدتك أكثر؟');
|
| 224 |
-
}, 1000);
|
| 225 |
-
|
| 226 |
input.value = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
}
|
| 228 |
}
|
| 229 |
|
|
@@ -236,16 +250,27 @@
|
|
| 236 |
messages.scrollTop = messages.scrollHeight;
|
| 237 |
}
|
| 238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
// دالة لإضافة رسالة ترحيب عند تحميل الصفحة
|
| 240 |
function initializeMessages() {
|
| 241 |
var today = new Date();
|
| 242 |
var hour = today.getHours();
|
| 243 |
var greeting = hour < 12 ? 'صباح الخير' : 'مساء الخير';
|
| 244 |
-
appendMessage('bot-message', `أهلاً
|
| 245 |
}
|
| 246 |
|
| 247 |
-
// استدعاء
|
| 248 |
-
initializeMessages
|
| 249 |
</script>
|
| 250 |
</body>
|
| 251 |
</html>
|
|
|
|
| 14 |
height: 100vh;
|
| 15 |
background-color: #f0f0f0;
|
| 16 |
}
|
|
|
|
| 17 |
.sidebar {
|
| 18 |
width: 260px;
|
| 19 |
background-color: #ffffff;
|
|
|
|
| 23 |
border-left: 1px solid #e0e0e0;
|
| 24 |
overflow-y: auto;
|
| 25 |
}
|
|
|
|
| 26 |
.logo {
|
| 27 |
font-size: 28px;
|
| 28 |
font-weight: bold;
|
|
|
|
| 30 |
text-align: center;
|
| 31 |
color: #333;
|
| 32 |
}
|
|
|
|
| 33 |
.menu-item {
|
| 34 |
padding: 10px;
|
| 35 |
margin-bottom: 5px;
|
| 36 |
cursor: pointer;
|
| 37 |
border-radius: 5px;
|
| 38 |
}
|
|
|
|
| 39 |
.menu-item:hover {
|
| 40 |
background-color: #f0f0f0;
|
| 41 |
}
|
|
|
|
| 42 |
.main-content {
|
| 43 |
flex-grow: 1;
|
| 44 |
display: flex;
|
| 45 |
flex-direction: column;
|
| 46 |
padding: 20px;
|
| 47 |
}
|
|
|
|
| 48 |
.header {
|
| 49 |
display: flex;
|
| 50 |
justify-content: space-between;
|
|
|
|
| 55 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 56 |
margin-bottom: 20px;
|
| 57 |
}
|
|
|
|
| 58 |
.header-title {
|
| 59 |
font-size: 24px;
|
| 60 |
font-weight: bold;
|
| 61 |
color: #333;
|
| 62 |
}
|
|
|
|
| 63 |
.chat-container {
|
| 64 |
flex-grow: 1;
|
| 65 |
display: flex;
|
|
|
|
| 69 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 70 |
overflow: hidden;
|
| 71 |
}
|
|
|
|
| 72 |
.messages {
|
| 73 |
flex: 1;
|
| 74 |
overflow-y: auto;
|
| 75 |
padding: 15px;
|
| 76 |
background-color: #fafafa;
|
| 77 |
}
|
|
|
|
| 78 |
.message {
|
| 79 |
padding: 12px;
|
| 80 |
margin: 8px 0;
|
|
|
|
| 83 |
max-width: 70%;
|
| 84 |
word-break: break-word;
|
| 85 |
}
|
|
|
|
| 86 |
.user-message {
|
| 87 |
text-align: left;
|
| 88 |
background-color: #e0e0e0;
|
| 89 |
margin-right: auto;
|
| 90 |
}
|
|
|
|
| 91 |
.bot-message {
|
| 92 |
text-align: right;
|
| 93 |
background-color: #f5f5f5;
|
| 94 |
margin-left: auto;
|
| 95 |
}
|
|
|
|
| 96 |
.input-container {
|
| 97 |
display: flex;
|
| 98 |
padding: 12px;
|
| 99 |
background-color: #ffffff;
|
| 100 |
border-top: 1px solid #e0e0e0;
|
| 101 |
}
|
|
|
|
| 102 |
.input-container input {
|
| 103 |
flex: 1;
|
| 104 |
padding: 12px;
|
|
|
|
| 107 |
margin-left: 10px;
|
| 108 |
font-size: 16px;
|
| 109 |
}
|
|
|
|
| 110 |
.input-container button {
|
| 111 |
padding: 12px 24px;
|
| 112 |
border-radius: 12px;
|
|
|
|
| 116 |
cursor: pointer;
|
| 117 |
font-size: 16px;
|
| 118 |
}
|
|
|
|
| 119 |
.input-container button:hover {
|
| 120 |
background-color: #666;
|
| 121 |
}
|
|
|
|
| 122 |
.quick-actions {
|
| 123 |
display: flex;
|
| 124 |
justify-content: center;
|
| 125 |
margin-top: 20px;
|
| 126 |
}
|
|
|
|
| 127 |
.action-button {
|
| 128 |
background-color: #f0f0f0;
|
| 129 |
color: #333;
|
|
|
|
| 133 |
border-radius: 5px;
|
| 134 |
cursor: pointer;
|
| 135 |
}
|
|
|
|
| 136 |
footer {
|
| 137 |
text-align: center;
|
| 138 |
padding: 15px;
|
|
|
|
| 141 |
margin-top: 20px;
|
| 142 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 143 |
}
|
|
|
|
| 144 |
@media (max-width: 768px) {
|
| 145 |
.sidebar {
|
| 146 |
display: none;
|
| 147 |
}
|
| 148 |
}
|
| 149 |
+
.loading {
|
| 150 |
+
display: none;
|
| 151 |
+
text-align: center;
|
| 152 |
+
padding: 10px;
|
| 153 |
+
}
|
| 154 |
+
.loading.visible {
|
| 155 |
+
display: block;
|
| 156 |
+
}
|
| 157 |
</style>
|
| 158 |
</head>
|
| 159 |
<body>
|
|
|
|
| 177 |
<div class="messages" id="messages">
|
| 178 |
<!-- Messages will be displayed here -->
|
| 179 |
</div>
|
| 180 |
+
<div class="loading" id="loading">جاري التحميل...</div>
|
| 181 |
<div class="input-container">
|
| 182 |
+
<input type="text" id="message-input" placeholder="اكتب رسالتك..." onkeypress="handleKeyPress(event)">
|
| 183 |
<button onclick="sendMessage()">إرسال</button>
|
| 184 |
</div>
|
| 185 |
</div>
|
| 186 |
|
| 187 |
<div class="quick-actions">
|
| 188 |
+
<button class="action-button" onclick="sendQuickMessage('إنشاء صورة')">إنشاء صورة</button>
|
| 189 |
+
<button class="action-button" onclick="sendQuickMessage('شرح موضوع')">شرح موضوع</button>
|
| 190 |
+
<button class="action-button" onclick="sendQuickMessage('شكر المقابل')">شكر المقابل</button>
|
| 191 |
+
<button class="action-button" onclick="sendQuickMessage('حقيقة مثيرة')">حقيقة مثيرة</button>
|
| 192 |
</div>
|
| 193 |
|
| 194 |
<footer>
|
|
|
|
| 197 |
</div>
|
| 198 |
|
| 199 |
<script>
|
| 200 |
+
// إضافة متغير للتحكم ��ي حالة الإرسال
|
| 201 |
+
let isSending = false;
|
| 202 |
+
|
| 203 |
+
async function sendMessage() {
|
| 204 |
+
if (isSending) return;
|
| 205 |
+
|
| 206 |
var input = document.getElementById('message-input');
|
| 207 |
var message = input.value.trim();
|
|
|
|
| 208 |
if (message !== '') {
|
| 209 |
+
isSending = true;
|
| 210 |
+
|
| 211 |
+
// إظهار الرسالة في الشات
|
| 212 |
appendMessage('user-message', message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
input.value = '';
|
| 214 |
+
|
| 215 |
+
// إظهار مؤشر التحميل
|
| 216 |
+
document.getElementById('loading').classList.add('visible');
|
| 217 |
+
|
| 218 |
+
try {
|
| 219 |
+
// إرسال الرسالة إلى Python/Streamlit
|
| 220 |
+
const response = await fetch('/_stcore/message', {
|
| 221 |
+
method: 'POST',
|
| 222 |
+
headers: {
|
| 223 |
+
'Content-Type': 'application/json',
|
| 224 |
+
},
|
| 225 |
+
body: JSON.stringify({ message: message })
|
| 226 |
+
});
|
| 227 |
+
|
| 228 |
+
if (response.ok) {
|
| 229 |
+
const data = await response.json();
|
| 230 |
+
appendMessage('bot-message', data.response);
|
| 231 |
+
} else {
|
| 232 |
+
appendMessage('bot-message', 'عذراً، حدث خطأ في معالجة رسالتك.');
|
| 233 |
+
}
|
| 234 |
+
} catch (error) {
|
| 235 |
+
appendMessage('bot-message', 'عذراً، حدث خطأ في الاتصال.');
|
| 236 |
+
} finally {
|
| 237 |
+
// إخفاء مؤشر التحميل وإعادة تعيين حالة الإرسال
|
| 238 |
+
document.getElementById('loading').classList.remove('visible');
|
| 239 |
+
isSending = false;
|
| 240 |
+
}
|
| 241 |
}
|
| 242 |
}
|
| 243 |
|
|
|
|
| 250 |
messages.scrollTop = messages.scrollHeight;
|
| 251 |
}
|
| 252 |
|
| 253 |
+
function handleKeyPress(event) {
|
| 254 |
+
if (event.key === 'Enter') {
|
| 255 |
+
sendMessage();
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
function sendQuickMessage(message) {
|
| 260 |
+
document.getElementById('message-input').value = message;
|
| 261 |
+
sendMessage();
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
// دالة لإضافة رسالة ترحيب عند تحميل الصفحة
|
| 265 |
function initializeMessages() {
|
| 266 |
var today = new Date();
|
| 267 |
var hour = today.getHours();
|
| 268 |
var greeting = hour < 12 ? 'صباح الخير' : 'مساء الخير';
|
| 269 |
+
appendMessage('bot-message', `أهلاً بك، ${greeting}! كيف يمكنني مساعدتك اليوم؟`);
|
| 270 |
}
|
| 271 |
|
| 272 |
+
// استدعاء دالة التهيئة عند تحميل الصفحة
|
| 273 |
+
window.onload = initializeMessages;
|
| 274 |
</script>
|
| 275 |
</body>
|
| 276 |
</html>
|