Spaces:
Paused
Paused
Upload index.html
Browse files- index.html +91 -0
index.html
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 6 |
+
<title>Chatbot Tester</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: sans-serif;
|
| 10 |
+
max-width: 600px;
|
| 11 |
+
margin: 2rem auto;
|
| 12 |
+
padding: 1rem;
|
| 13 |
+
background: #f9f9f9;
|
| 14 |
+
}
|
| 15 |
+
label, select, input, button {
|
| 16 |
+
display: block;
|
| 17 |
+
width: 100%;
|
| 18 |
+
margin-bottom: 1rem;
|
| 19 |
+
}
|
| 20 |
+
#response {
|
| 21 |
+
background: #fff;
|
| 22 |
+
padding: 1rem;
|
| 23 |
+
border-radius: 4px;
|
| 24 |
+
box-shadow: 0 0 4px rgba(0,0,0,0.1);
|
| 25 |
+
}
|
| 26 |
+
audio {
|
| 27 |
+
margin-top: 1rem;
|
| 28 |
+
width: 100%;
|
| 29 |
+
}
|
| 30 |
+
</style>
|
| 31 |
+
</head>
|
| 32 |
+
<body>
|
| 33 |
+
<h1>Chatbot Tester</h1>
|
| 34 |
+
|
| 35 |
+
<label for="message">Your Message</label>
|
| 36 |
+
<input type="text" id="message" placeholder="Type your question here…" />
|
| 37 |
+
|
| 38 |
+
<label for="gender">Gender</label>
|
| 39 |
+
<select id="gender">
|
| 40 |
+
<option value="female">Female</option>
|
| 41 |
+
<option value="male">Male</option>
|
| 42 |
+
</select>
|
| 43 |
+
|
| 44 |
+
<button id="sendBtn">Send</button>
|
| 45 |
+
|
| 46 |
+
<div id="response">
|
| 47 |
+
<p id="replyText">The reply will appear here.</p>
|
| 48 |
+
<audio id="replyAudio" controls hidden></audio>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<script>
|
| 52 |
+
const sendBtn = document.getElementById('sendBtn');
|
| 53 |
+
const messageInput = document.getElementById('message');
|
| 54 |
+
const genderSelect = document.getElementById('gender');
|
| 55 |
+
const replyText = document.getElementById('replyText');
|
| 56 |
+
const replyAudio = document.getElementById('replyAudio');
|
| 57 |
+
|
| 58 |
+
sendBtn.addEventListener('click', async () => {
|
| 59 |
+
const msg = messageInput.value.trim();
|
| 60 |
+
const gender = genderSelect.value;
|
| 61 |
+
if (!msg) {
|
| 62 |
+
alert('Please enter a message.');
|
| 63 |
+
return;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
replyText.textContent = 'Loading…';
|
| 67 |
+
replyAudio.hidden = true;
|
| 68 |
+
replyAudio.src = '';
|
| 69 |
+
|
| 70 |
+
try {
|
| 71 |
+
const res = await fetch('http://192.168.0.119:5000/chat', {
|
| 72 |
+
method: 'POST',
|
| 73 |
+
headers: { 'Content-Type': 'application/json' },
|
| 74 |
+
body: JSON.stringify({ message: msg, gender })
|
| 75 |
+
});
|
| 76 |
+
const data = await res.json();
|
| 77 |
+
|
| 78 |
+
if (res.ok) {
|
| 79 |
+
replyText.textContent = data.response;
|
| 80 |
+
replyAudio.src = data.audio_file;
|
| 81 |
+
replyAudio.hidden = false;
|
| 82 |
+
} else {
|
| 83 |
+
replyText.textContent = 'Error: ' + (data.error || res.statusText);
|
| 84 |
+
}
|
| 85 |
+
} catch (err) {
|
| 86 |
+
replyText.textContent = 'Fetch error: ' + err.message;
|
| 87 |
+
}
|
| 88 |
+
});
|
| 89 |
+
</script>
|
| 90 |
+
</body>
|
| 91 |
+
</html>
|