-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsamp.html
More file actions
113 lines (100 loc) · 3.51 KB
/
samp.html
File metadata and controls
113 lines (100 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chatbot Interface</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 0;
background-color: #f4f4f4;
}
#chat-container {
background: white;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 600px;
margin: auto;
}
#output {
height: 300px;
overflow-y: auto;
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
margin-bottom: 10px;
background-color: #e9ecef;
}
input[type="text"] {
width: calc(100% - 22px);
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}
button {
padding: 10px;
border-radius: 5px;
border: none;
background-color: #007bff;
color: white;
}
</style>
</head>
<body>
<div id="chat-container">
<h2>AI Chatbot</h2>
<div id="output"></div>
<input type="text" id="user-input" placeholder="Type your message here..." />
<button id="send-button">Send</button>
</div>
<script>
const outputDiv = document.getElementById('output');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
sendButton.onclick = async function() {
const userMessage = userInput.value.trim();
if (!userMessage) return;
appendMessage(`User: ${userMessage}`);
userInput.value = '';
try {
const response = await getChatbotResponse(userMessage);
appendMessage(`Chatbot: ${response}`);
} catch (error) {
appendMessage(`Chatbot: Error occurred. Please try again.`);
}
};
async function getChatbotResponse(message) {
const response = await fetch('http://127.0.0.1:5000/chat', { // Update this line
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: message })
});
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
return data.response; // Adjust based on your API's response format
}
/*async function getChatbotResponse(message) {
const response = await fetch('https://your-backend-api-url.com/chat', { // Replace with your backend API URL
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY' // Replace with your API key if needed
},
body: JSON.stringify({ prompt: message })
});
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
return data.response; // Adjust based on your API's response format
}*/
function appendMessage(message) {
outputDiv.innerHTML += `<div>${message}</div>`;
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to the bottom
}
</script>
</body>
</html>