Spaces:
Running
Running
<html lang="fa" dir="rtl"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>دستیار هوش مصنوعی</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
background-color: #f9f9f9; | |
text-align: center; | |
padding: 20px; | |
} | |
#chat-container { | |
width: 100%; | |
max-width: 600px; | |
margin: 0 auto; | |
background: white; | |
border: 1px solid #ddd; | |
border-radius: 10px; | |
padding: 20px; | |
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); | |
} | |
#messages { | |
max-height: 300px; | |
overflow-y: auto; | |
margin-bottom: 20px; | |
text-align: left; | |
} | |
.message { | |
margin-bottom: 10px; | |
padding: 10px; | |
border-radius: 5px; | |
} | |
.user-message { | |
background-color: #d1ecf1; | |
text-align: right; | |
} | |
.assistant-message { | |
background-color: #f8d7da; | |
text-align: left; | |
} | |
#user-input { | |
width: 100%; | |
padding: 10px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
} | |
#send-button { | |
margin-top: 10px; | |
padding: 10px 20px; | |
background-color: #007bff; | |
color: white; | |
border: none; | |
border-radius: 5px; | |
cursor: pointer; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chat-container"> | |
<div id="messages"></div> | |
<textarea id="user-input" placeholder="پیام خود را وارد کنید..."></textarea> | |
<button id="send-button">ارسال</button> | |
</div> | |
<script> | |
const sendButton = document.getElementById("send-button"); | |
const userInput = document.getElementById("user-input"); | |
const messagesDiv = document.getElementById("messages"); | |
sendButton.addEventListener("click", async () => { | |
const userMessage = userInput.value; | |
if (!userMessage) return; | |
// نمایش پیام کاربر | |
const userDiv = document.createElement("div"); | |
userDiv.className = "message user-message"; | |
userDiv.textContent = userMessage; | |
messagesDiv.appendChild(userDiv); | |
// ارسال پیام به استریملیت | |
const response = await fetch("/generate", { | |
method: "POST", | |
headers: { "Content-Type": "application/json" }, | |
body: JSON.stringify({ message: userMessage }), | |
}); | |
const data = await response.json(); | |
// نمایش پاسخ مدل | |
const assistantDiv = document.createElement("div"); | |
assistantDiv.className = "message assistant-message"; | |
assistantDiv.textContent = data.response; | |
messagesDiv.appendChild(assistantDiv); | |
userInput.value = ""; | |
messagesDiv.scrollTop = messagesDiv.scrollHeight; | |
}); | |
</script> | |
</body> | |
</html> | |