-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage.html
193 lines (147 loc) · 3.75 KB
/
language.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<html>
<head>
<style>
* {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
font-family: 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', Arial, Helvetica,
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: silver;
height: 100%;
margin: 0;
}
span {
padding-right: 15px;
padding-left: 15px;
}
.container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
.chat {
height: 300px;
width: 50vw;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
::-webkit-input-placeholder {
color: .711
}
input {
border: 0;
padding: 15px;
margin-left: auto;
border-radius: 10px;
}
.messages {
display: flex;
flex-direction: column;
overflow: scroll;
height: 90%;
width: 100%;
background-color: white;
padding: 15px;
margin: 15px;
border-radius: 10px;
}
#bot {
margin-right: auto;
}
#user {
margin-left: auto;
}
.bot {
font-family: Consolas, 'Courier New', Menlo, source-code-pro, Monaco,
monospace;
}
.avatar {
height: 25px;
}
.response {
display: flex;
align-items: center;
margin: 1%;
}
/* Mobile */
@media only screen and (max-width: 980px) {
.container {
flex-direction: column;
justify-content: flex-start;
}
.chat {
width: 75vw;
margin: 10vw;
}
}
</style>
</head>
<body>
<h1>Spanish dialogue practice. Target: you are visiting a hotel in Cancún, Mexico and want to book a room.</h1>
<div id="container" class="container">
<img src="receptionist.jpg" height="400vh" alt="Chatbot clipart">
<div id="chat" class="chat">
<div id="messages" class="messages">Bienvenidos al hotel Paraiso Cancún. En qué les puedo ayudar?</div>
<input id="input" type="text" placeholder="Write something..." autocomplete="off" autofocus="true" />
</div>
</div>
<script>//<!--
let conversation = [];
conversation.push({"role":"assistant", "content":"Bienvenidos al hotel Paraiso Cancún. En qué les puedo ayudar?"});
const inputField = document.getElementById("input");
inputField.addEventListener("keydown", (e) => {
if (e.code === "Enter" || e.code === "NumpadEnter" || e.keyCode === 13) {
let input = inputField.value;
inputField.value = "";
output(input);
}
});
async function output(input) {
conversation.push({"role":"user", "content":input});
var history = JSON.stringify(conversation);
var jsonified_history = encodeURIComponent(history);
let response = await fetch('https://languagetutorfunctionapp.azurewebsites.net/api/UserInput?history=' + jsonified_history);
let product = await response.text();
conversation.push({"role":"assistant", "content":product});
addChatEntry(input, product);
/*
fetch( 'https://fastdatasciencechatbot.azurewebsites.net/api/UserInput?history=' + jsonified_history)
.then( response => {
alert(response.json());
let product = response.text();
conversation.push({"role":"assistant", "content":product});
addChatEntry(input, product);
} );
*/
}
function addChatEntry(input, product) {
const messagesContainer = document.getElementById("messages");
let userDiv = document.createElement("div");
userDiv.id = "user";
userDiv.className = "user response";
userDiv.innerHTML = `<span>${input}</span>`;
messagesContainer.appendChild(userDiv);
let botDiv = document.createElement("div");
let botText = document.createElement("span");
botDiv.id = "bot";
botDiv.className = "bot response";
botText.innerText = `${product}`;
botDiv.appendChild(botText);
messagesContainer.appendChild(botDiv);
messagesContainer.scrollTop =
messagesContainer.scrollHeight - messagesContainer.clientHeight;
}
--></script>
</body>
</html>