Really-amin commited on
Commit
a4dcebc
·
verified ·
1 Parent(s): 1ca069a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +22 -27
index.html CHANGED
@@ -3,16 +3,15 @@
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://cdn.jsdelivr.net/gh/rastikerdar/[email protected]/Vazirmatn-font-face.css" rel="stylesheet" type="text/css" />
8
  <style>
9
  body {
10
- font-family: 'Vazirmatn', sans-serif;
11
  background-color: #f9f9f9;
12
  text-align: center;
13
  padding: 20px;
14
  }
15
- #chat-box {
16
  width: 100%;
17
  max-width: 600px;
18
  margin: 0 auto;
@@ -20,6 +19,7 @@
20
  border: 1px solid #ddd;
21
  border-radius: 10px;
22
  padding: 20px;
 
23
  }
24
  #messages {
25
  max-height: 300px;
@@ -32,11 +32,11 @@
32
  padding: 10px;
33
  border-radius: 5px;
34
  }
35
- .user {
36
  background-color: #d1ecf1;
37
  text-align: right;
38
  }
39
- .assistant {
40
  background-color: #f8d7da;
41
  text-align: left;
42
  }
@@ -55,49 +55,44 @@
55
  border-radius: 5px;
56
  cursor: pointer;
57
  }
58
- #send-button:hover {
59
- background-color: #0056b3;
60
- }
61
  </style>
62
  </head>
63
  <body>
64
- <div id="chat-box">
65
  <div id="messages"></div>
66
- <textarea id="user-input" placeholder="پیامتان را بنویسید..."></textarea>
67
  <button id="send-button">ارسال</button>
68
  </div>
69
  <script>
70
- const messagesDiv = document.getElementById('messages');
71
- const userInput = document.getElementById('user-input');
72
- const sendButton = document.getElementById('send-button');
73
 
74
- sendButton.addEventListener('click', async () => {
75
  const userMessage = userInput.value;
76
  if (!userMessage) return;
77
 
78
  // نمایش پیام کاربر
79
- const userDiv = document.createElement('div');
80
- userDiv.className = 'message user';
81
  userDiv.textContent = userMessage;
82
  messagesDiv.appendChild(userDiv);
83
 
84
- // ارسال پیام به بک‌اند
85
- const response = await fetch('/api/chat', {
86
- method: 'POST',
87
- headers: {
88
- 'Content-Type': 'application/json'
89
- },
90
- body: JSON.stringify({ message: userMessage })
91
  });
92
  const data = await response.json();
93
 
94
  // نمایش پاسخ مدل
95
- const assistantDiv = document.createElement('div');
96
- assistantDiv.className = 'message assistant';
97
  assistantDiv.textContent = data.response;
98
  messagesDiv.appendChild(assistantDiv);
99
 
100
- userInput.value = '';
101
  messagesDiv.scrollTop = messagesDiv.scrollHeight;
102
  });
103
  </script>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>دستیار هوش مصنوعی</title>
 
7
  <style>
8
  body {
9
+ font-family: Arial, sans-serif;
10
  background-color: #f9f9f9;
11
  text-align: center;
12
  padding: 20px;
13
  }
14
+ #chat-container {
15
  width: 100%;
16
  max-width: 600px;
17
  margin: 0 auto;
 
19
  border: 1px solid #ddd;
20
  border-radius: 10px;
21
  padding: 20px;
22
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
23
  }
24
  #messages {
25
  max-height: 300px;
 
32
  padding: 10px;
33
  border-radius: 5px;
34
  }
35
+ .user-message {
36
  background-color: #d1ecf1;
37
  text-align: right;
38
  }
39
+ .assistant-message {
40
  background-color: #f8d7da;
41
  text-align: left;
42
  }
 
55
  border-radius: 5px;
56
  cursor: pointer;
57
  }
 
 
 
58
  </style>
59
  </head>
60
  <body>
61
+ <div id="chat-container">
62
  <div id="messages"></div>
63
+ <textarea id="user-input" placeholder="پیام خود را وارد کنید..."></textarea>
64
  <button id="send-button">ارسال</button>
65
  </div>
66
  <script>
67
+ const sendButton = document.getElementById("send-button");
68
+ const userInput = document.getElementById("user-input");
69
+ const messagesDiv = document.getElementById("messages");
70
 
71
+ sendButton.addEventListener("click", async () => {
72
  const userMessage = userInput.value;
73
  if (!userMessage) return;
74
 
75
  // نمایش پیام کاربر
76
+ const userDiv = document.createElement("div");
77
+ userDiv.className = "message user-message";
78
  userDiv.textContent = userMessage;
79
  messagesDiv.appendChild(userDiv);
80
 
81
+ // ارسال پیام به استریم‌لیت
82
+ const response = await fetch("/generate", {
83
+ method: "POST",
84
+ headers: { "Content-Type": "application/json" },
85
+ body: JSON.stringify({ message: userMessage }),
 
 
86
  });
87
  const data = await response.json();
88
 
89
  // نمایش پاسخ مدل
90
+ const assistantDiv = document.createElement("div");
91
+ assistantDiv.className = "message assistant-message";
92
  assistantDiv.textContent = data.response;
93
  messagesDiv.appendChild(assistantDiv);
94
 
95
+ userInput.value = "";
96
  messagesDiv.scrollTop = messagesDiv.scrollHeight;
97
  });
98
  </script>