KarthikaRajagopal
commited on
Upload index.html
Browse files- index.html +216 -0
index.html
ADDED
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Agri Chatbot</title>
|
5 |
+
<link rel="icon" type="image/x-icon" href="static/images/favicon.ico">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<meta name="description" content="This is an Agriculture chatbot that helps farmers to make write desitions." />
|
8 |
+
<link rel="icon" type="image/png" href="static/images/favicon.ico"/>
|
9 |
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
|
10 |
+
<!-- Option 1: Include in HTML -->
|
11 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
|
12 |
+
<style>
|
13 |
+
.loading-message {
|
14 |
+
text-align: center;
|
15 |
+
font-style: italic;
|
16 |
+
color: #999;
|
17 |
+
}
|
18 |
+
|
19 |
+
#chat-container {
|
20 |
+
height: 60vh;
|
21 |
+
overflow-y: auto;
|
22 |
+
}
|
23 |
+
|
24 |
+
#user-input {
|
25 |
+
margin-bottom: 10px;
|
26 |
+
}
|
27 |
+
</style>
|
28 |
+
</head>
|
29 |
+
<body>
|
30 |
+
<div class="container">
|
31 |
+
<h1>Krissi Help Chatbot</h1>
|
32 |
+
<p>Disclaimer:please have patience this might take some time</p>
|
33 |
+
<div class="row chat-container" id="chat-container"></div>
|
34 |
+
<div class="row">
|
35 |
+
<div class="col-xs-12">
|
36 |
+
<input type="text" class="form-control" id="user-input" placeholder="Type your message...">
|
37 |
+
</div>
|
38 |
+
</div>
|
39 |
+
<div class="row">
|
40 |
+
<div class="col-xs-12">
|
41 |
+
<button class="btn btn-primary btn-block" id="send-btn">Send</button>
|
42 |
+
</div>
|
43 |
+
</div>
|
44 |
+
|
45 |
+
<div class="row">
|
46 |
+
<div class="col-xs-12">
|
47 |
+
<button class="btn btn-primary btn-block" id="record-btn">Record</button>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
|
51 |
+
<div class="row">
|
52 |
+
<div class="col-xs-12">
|
53 |
+
<audio id="audio" controls></audio>
|
54 |
+
</div>
|
55 |
+
</div>
|
56 |
+
<footer class="footer">
|
57 |
+
<div class="footer-links">
|
58 |
+
<h2> Made by Mohammed Ashraf
|
59 |
+
<a href="https://www.linkedin.com/in/mohammed97ashraf" target="_blank"><i class="bi bi-linkedin"></i></a>
|
60 |
+
<a href="https://github.com/mohammed97ashraf" target="_blank"><i class="bi bi-github"></i></a></h2>
|
61 |
+
</div>
|
62 |
+
</footer>
|
63 |
+
</div>
|
64 |
+
|
65 |
+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
66 |
+
<script>
|
67 |
+
$(document).ready(function() {
|
68 |
+
$('#send-btn').on('click', function() {
|
69 |
+
sendMessage();
|
70 |
+
});
|
71 |
+
|
72 |
+
$('#user-input').on('keypress', function(e) {
|
73 |
+
if (e.which === 13) {
|
74 |
+
sendMessage();
|
75 |
+
}
|
76 |
+
});
|
77 |
+
|
78 |
+
$('#record-btn').on('click', function() {
|
79 |
+
toggleRecording();
|
80 |
+
});
|
81 |
+
|
82 |
+
var recording = false;
|
83 |
+
var recorder;
|
84 |
+
|
85 |
+
function toggleRecording() {
|
86 |
+
if (recording) {
|
87 |
+
stopRecording();
|
88 |
+
$('#record-btn').text('Record');
|
89 |
+
} else {
|
90 |
+
startRecording();
|
91 |
+
$('#record-btn').text('Stop Recording');
|
92 |
+
}
|
93 |
+
recording = !recording;
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
function startRecording() {
|
98 |
+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
99 |
+
navigator.mediaDevices.getUserMedia({ audio: true })
|
100 |
+
.then(function(stream) {
|
101 |
+
recorder = new MediaRecorder(stream);
|
102 |
+
var chunks = [];
|
103 |
+
|
104 |
+
recorder.addEventListener('dataavailable', function(e) {
|
105 |
+
chunks.push(e.data);
|
106 |
+
});
|
107 |
+
|
108 |
+
recorder.addEventListener('stop', function() {
|
109 |
+
var audioBlob = new Blob(chunks, { type: 'audio/webm' });
|
110 |
+
var formData = new FormData();
|
111 |
+
formData.append('audio', audioBlob, 'audio.webm');
|
112 |
+
sendAudio(formData);
|
113 |
+
});
|
114 |
+
|
115 |
+
recorder.start();
|
116 |
+
})
|
117 |
+
.catch(function(err) {
|
118 |
+
console.error('Error accessing microphone:', err);
|
119 |
+
});
|
120 |
+
} else {
|
121 |
+
console.error('getUserMedia is not supported in this browser.');
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
|
126 |
+
function stopRecording() {
|
127 |
+
if (recorder) {
|
128 |
+
recorder.stop();
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
function sendAudio(formData) {
|
133 |
+
$('#chat-container').append('<div class="col-xs-12"><p class="loading-message">Uploading audio...</p></div>');
|
134 |
+
scrollToBottom();
|
135 |
+
|
136 |
+
$.ajax({
|
137 |
+
url: '/chat',
|
138 |
+
type: 'POST',
|
139 |
+
data: formData,
|
140 |
+
contentType: false,
|
141 |
+
processData: false,
|
142 |
+
success: function(response) {
|
143 |
+
$('#chat-container .loading-message:last').remove();
|
144 |
+
|
145 |
+
var transcription = response.text;
|
146 |
+
$('#user-input').val(transcription);
|
147 |
+
sendMessage();
|
148 |
+
},
|
149 |
+
error: function(xhr, status, error) {
|
150 |
+
console.error('Error uploading audio:', error);
|
151 |
+
}
|
152 |
+
});
|
153 |
+
}
|
154 |
+
|
155 |
+
function sendMessage() {
|
156 |
+
var userInput = $('#user-input').val();
|
157 |
+
if (userInput.trim() !== '') {
|
158 |
+
$('#user-input').val('');
|
159 |
+
$('#chat-container').append('<div class="col-xs-12 text-right"><p class="alert alert-info">' + userInput + '</p></div>');
|
160 |
+
scrollToBottom();
|
161 |
+
|
162 |
+
$('#chat-container').append('<div class="col-xs-12"><p class="loading-message">Bot is typing...</p></div>');
|
163 |
+
scrollToBottom();
|
164 |
+
|
165 |
+
$.post('/chat', {text: userInput}, function(response) {
|
166 |
+
$('#chat-container .loading-message:last').remove();
|
167 |
+
|
168 |
+
$('#chat-container').append('<div class="col-xs-12 text-left"><p class="alert alert-success">' + response.text + '</p></div>');
|
169 |
+
scrollToBottom();
|
170 |
+
|
171 |
+
setVoice(response.voice);
|
172 |
+
playNotificationSound();
|
173 |
+
showNotification(response.text);
|
174 |
+
});
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
+
function setVoice(voiceFile) {
|
179 |
+
var audio = document.getElementById('audio');
|
180 |
+
audio.pause();
|
181 |
+
audio.src = voiceFile;
|
182 |
+
audio.load();
|
183 |
+
audio.play();
|
184 |
+
}
|
185 |
+
|
186 |
+
function playNotificationSound() {
|
187 |
+
var audio = new Audio('{{ url_for('static', filename='audio/sound.mp3') }}');
|
188 |
+
audio.play();
|
189 |
+
}
|
190 |
+
|
191 |
+
function showNotification(message) {
|
192 |
+
if (Notification.permission === "granted") {
|
193 |
+
var notification = new Notification("New Message", {
|
194 |
+
body: message,
|
195 |
+
icon: "{{ url_for('static', filename='img/notification-icon.png') }}"
|
196 |
+
});
|
197 |
+
} else if (Notification.permission !== "denied") {
|
198 |
+
Notification.requestPermission().then(function(permission) {
|
199 |
+
if (permission === "granted") {
|
200 |
+
var notification = new Notification("New Message", {
|
201 |
+
body: message,
|
202 |
+
icon: "{{ url_for('static', filename='img/notification-icon.png') }}"
|
203 |
+
});
|
204 |
+
}
|
205 |
+
});
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
function scrollToBottom() {
|
210 |
+
$('#chat-container').scrollTop($('#chat-container')[0].scrollHeight);
|
211 |
+
}
|
212 |
+
});
|
213 |
+
</script>
|
214 |
+
|
215 |
+
</body>
|
216 |
+
</html>
|