File size: 2,448 Bytes
265fc3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746b450
265fc3e
 
 
 
 
ef88068
 
 
 
265fc3e
ef88068
 
 
 
 
265fc3e
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Chatbot Tester</title>
  <style>
    body {
      font-family: sans-serif;
      max-width: 600px;
      margin: 2rem auto;
      padding: 1rem;
      background: #f9f9f9;
    }
    label, select, input, button {
      display: block;
      width: 100%;
      margin-bottom: 1rem;
    }
    #response {
      background: #fff;
      padding: 1rem;
      border-radius: 4px;
      box-shadow: 0 0 4px rgba(0,0,0,0.1);
    }
    audio {
      margin-top: 1rem;
      width: 100%;
    }
  </style>
</head>
<body>
  <h1>Chatbot Tester</h1>

  <label for="message">Your Message</label>
  <input type="text" id="message" placeholder="Type your question here…" />

  <label for="gender">Gender</label>
  <select id="gender">
    <option value="female">Female</option>
    <option value="male">Male</option>
  </select>

  <button id="sendBtn">Send</button>

  <div id="response">
    <p id="replyText">The reply will appear here.</p>
    <audio id="replyAudio" controls hidden></audio>
  </div>

  <script>
    const sendBtn = document.getElementById('sendBtn');
    const messageInput = document.getElementById('message');
    const genderSelect = document.getElementById('gender');
    const replyText = document.getElementById('replyText');
    const replyAudio = document.getElementById('replyAudio');

    sendBtn.addEventListener('click', async () => {
      const msg = messageInput.value.trim();
      const gender = genderSelect.value;
      if (!msg) {
        alert('Please enter a message.');
        return;
      }

      replyText.textContent = 'Loading…';
      replyAudio.hidden = true;
      replyAudio.src = '';

      try {
        const res = await fetch('/chat', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ message: msg, gender })
        });

        if (!res.ok) {
          const errorText = await res.text();
          replyText.textContent = 'Error: ' + errorText;
          return;
        }

        const data = await res.json();
        replyText.textContent = data.response;
        replyAudio.src = '/static/' + data.audiofile;
        replyAudio.hidden = false;
      } catch (err) {
        replyText.textContent = 'Fetch error: ' + err.message;
      }
    });
  </script>
</body>
</html>