-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.html
126 lines (107 loc) · 4.07 KB
/
input.html
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
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<title>Ask Llama Locally !</title>
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif, sans-serif;
margin: 20px;
background-color: #f0f0f0;
}
form, #conversation {
margin-bottom: 20px;
width: calc(100% - 40px); /* Adjusting for the 20px margin on each side */
}
input[type="text"], button {
width: calc(100% - 22px); /* Adjusting for padding and border */
box-sizing: border-box; /* To include padding and border in the width */
padding: 10px;
margin-bottom: 10px;
}
input[type="text"] {
font-size: 16px;
border: 2px solid gray;
background-color: transparent;
outline: none;
color: gray;
}
button {
font-size: 12px;
border: 2px solid #6aade4;
background-color: #6aade4;
color: white;
cursor: pointer;
}
#conversation {
border: 1px solid #ddd;
padding: 10px;
height: 600px;
overflow-y: auto;
background-color: #fff;
}
.conversation-entry {
padding: 5px;
margin-bottom: 5px;
border-radius: 5px;
}
.question {
background-color: rgb(233, 240, 218); /* Light blue background for questions */
}
.answer {
background-color: rgb(183, 209, 237); /* Light red background for answers */
}
</style>
</head>
<body>
<h3> <i>Ask Llama Locally.</i></h3>
<form id="messageForm">
<input type="text" name="message" placeholder="Enter text here">
<button type="submit">Send</button>
</form>
<div id="conversation"></div>
<div id="loading" style="display: none;">Loading...</div>
<script>
document.getElementById('messageForm').addEventListener('submit', function(event) {
event.preventDefault();
const messageInput = document.getElementsByName('message')[0];
const message = messageInput.value;
const conversation = document.getElementById('conversation');
const loadingIndicator = document.getElementById('loading');
// Show loading indicator
loadingIndicator.style.display = 'block';
const startTime = new Date();
// Create question div and append it
const questionDiv = document.createElement('div');
questionDiv.textContent = `Question: ${message}`;
questionDiv.classList.add('conversation-entry', 'question');
conversation.appendChild(questionDiv);
fetch('/sendMessage', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `message=${encodeURIComponent(message)}`
})
.then(response => response.text())
.then(data => {
const endTime = new Date();
const responseTime = (endTime - startTime) / 1000; // Time in seconds
// Hide loading indicator
loadingIndicator.style.display = 'none';
// Create answer div and append it
const answerDiv = document.createElement('div');
answerDiv.innerHTML = `Answer: ${data}<br><small>Response time: ${responseTime} seconds</small>`;
answerDiv.classList.add('conversation-entry', 'answer');
conversation.appendChild(answerDiv);
})
.catch(error => {
console.error('Error:', error);
// Hide loading indicator in case of error
loadingIndicator.style.display = 'none';
});
// Clear the input field
messageInput.value = '';
});
</script>
</body>
</html>