File size: 2,770 Bytes
b0fc348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Customer Support Chatbot</title>
  <style>
    :root {
      --color-accent: #6366f1;
      --color-background: #0f172a;
      --color-surface: #1e293b;
      --color-text: #e2e8f0;
      --boxSize: 8px;
      --gutter: 4px;
    }
    body {
      margin: 0;
      padding: 0;
      background-color: var(--color-background);
      color: var(--color-text);
      font-family: system-ui, -apple-system, sans-serif;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .container {
      width: 90%;
      max-width: 800px;
      background-color: var(--color-surface);
      padding: 2rem;
      border-radius: 1rem;
      box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
      text-align: center;
    }
    .input-group {
      margin: 1rem 0;
    }
    input {
      padding: 0.75rem;
      border-radius: 0.5rem;
      border: 1px solid rgba(255, 255, 255, 0.1);
      background-color: var(--color-background);
      color: var(--color-text);
      font-size: 1rem;
      width: 100%;
      box-sizing: border-box;
    }
    button {
      padding: 1rem 2rem;
      border-radius: 0.5rem;
      border: none;
      background-color: var(--color-accent);
      color: white;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.2s ease;
    }
    button:hover {
      opacity: 0.9;
      transform: translateY(-1px);
    }
    #response {
      margin-top: 1rem;
      background-color: var(--color-surface);
      padding: 1rem;
      border-radius: 0.5rem;
      text-align: left;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>Customer Support Chatbot</h1>
    <p>Ask your question below:</p>
    <div class="input-group">
      <input type="text" id="query" placeholder="Type your question here">
    </div>
    <button id="submit-button">Submit</button>
    <div id="response"></div>
  </div>

  <script>
    document.getElementById('submit-button').addEventListener('click', async () => {
      const query = document.getElementById('query').value;
      const responseDiv = document.getElementById('response');
      responseDiv.innerHTML = "<em>Loading...</em>";
      try {
        const res = await fetch('/chat', {
          method: 'POST',
          headers: {'Content-Type': 'application/json'},
          body: JSON.stringify({question: query})
        });
        const data = await res.json();
        responseDiv.innerHTML = data.answer;
      } catch (err) {
        responseDiv.innerHTML = "<em>Error retrieving answer.</em>";
      }
    });
  </script>
</body>
</html>