Spaces:
Running
Running
Update index.html
Browse files- index.html +77 -18
index.html
CHANGED
|
@@ -1,19 +1,78 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="fa" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>دستیار هوش مصنوعی پیشرفته</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap" rel="stylesheet">
|
| 8 |
+
<link rel="stylesheet" href="styles.css">
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<div id="chat-container">
|
| 12 |
+
<div id="chat-header">
|
| 13 |
+
<span>دستیار هوش مصنوعی پیشرفته</span>
|
| 14 |
+
<button id="theme-toggle">🌓</button>
|
| 15 |
+
</div>
|
| 16 |
+
<div id="chat-messages"></div>
|
| 17 |
+
<div id="input-container">
|
| 18 |
+
<input type="text" id="user-input" placeholder="سوال خود را اینجا بنویسید...">
|
| 19 |
+
<button id="send-button">ارسال</button>
|
| 20 |
+
</div>
|
| 21 |
+
</div>
|
| 22 |
+
|
| 23 |
+
<script>
|
| 24 |
+
const chatMessages = document.getElementById('chat-messages');
|
| 25 |
+
const userInput = document.getElementById('user-input');
|
| 26 |
+
const sendButton = document.getElementById('send-button');
|
| 27 |
+
const themeToggle = document.getElementById('theme-toggle');
|
| 28 |
+
|
| 29 |
+
function addMessage(text, isUser) {
|
| 30 |
+
const messageDiv = document.createElement('div');
|
| 31 |
+
messageDiv.classList.add('message');
|
| 32 |
+
messageDiv.classList.add(isUser ? 'user-message' : 'assistant-message');
|
| 33 |
+
messageDiv.textContent = text;
|
| 34 |
+
chatMessages.appendChild(messageDiv);
|
| 35 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
async function sendMessage() {
|
| 39 |
+
const message = userInput.value.trim();
|
| 40 |
+
if (message) {
|
| 41 |
+
addMessage(message, true);
|
| 42 |
+
userInput.value = '';
|
| 43 |
+
|
| 44 |
+
try {
|
| 45 |
+
const response = await fetch('/generate', {
|
| 46 |
+
method: 'POST',
|
| 47 |
+
headers: {
|
| 48 |
+
'Content-Type': 'application/json',
|
| 49 |
+
},
|
| 50 |
+
body: JSON.stringify({ prompt: message }),
|
| 51 |
+
});
|
| 52 |
+
const data = await response.json();
|
| 53 |
+
addMessage(data.response, false);
|
| 54 |
+
} catch (error) {
|
| 55 |
+
console.error('Error:', error);
|
| 56 |
+
addMessage('متأسفم، مشکلی پیش آمد.', false);
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function toggleTheme() {
|
| 62 |
+
document.body.classList.toggle('dark-theme');
|
| 63 |
+
themeToggle.textContent = document.body.classList.contains('dark-theme') ? '☀️' : '🌓';
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
sendButton.addEventListener('click', sendMessage);
|
| 67 |
+
userInput.addEventListener('keypress', function(e) {
|
| 68 |
+
if (e.key === 'Enter') {
|
| 69 |
+
sendMessage();
|
| 70 |
+
}
|
| 71 |
+
});
|
| 72 |
+
themeToggle.addEventListener('click', toggleTheme);
|
| 73 |
+
|
| 74 |
+
// پیام خوشآمدگویی
|
| 75 |
+
addMessage('سلام! من دستیار هوش مصنوعی شما هستم. چطور میتوانم کمکتان کنم؟', false);
|
| 76 |
+
</script>
|
| 77 |
+
</body>
|
| 78 |
</html>
|