File size: 4,037 Bytes
f5e2bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>πŸ‡²πŸ‡¦ Moroccan Tourism Assistant</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <style>

        body {

            font-family: Arial, sans-serif;

            max-width: 800px;

            margin: 20px auto;

            padding: 0 20px;

        }

        .chat-container {

            border: 1px solid #ccc;

            border-radius: 5px;

            padding: 20px;

            height: 400px;

            overflow-y: auto;

            margin-bottom: 20px;

        }

        .message {

            margin: 10px 0;

            padding: 10px;

            border-radius: 5px;

        }

        .user-message {

            background-color: #e3f2fd;

            margin-left: 20%;

        }

        .bot-message {

            background-color: #f5f5f5;

            margin-right: 20%;

        }

        .input-container {

            display: flex;

            gap: 10px;

        }

        #user-input {

            flex-grow: 1;

            padding: 10px;

            border: 1px solid #ccc;

            border-radius: 5px;

        }

        button {

            padding: 10px 20px;

            background-color: #007bff;

            color: white;

            border: none;

            border-radius: 5px;

            cursor: pointer;

        }

        button:hover {

            background-color: #0056b3;

        }

        .loading {

            display: none;

            margin: 10px 0;

            color: #666;

        }

    </style>
</head>
<body>
    <h1>πŸ‡²πŸ‡¦ Moroccan Tourism Assistant</h1>
    <div class="chat-container" id="chat-container"></div>
    <div class="loading" id="loading">Assistant is thinking...</div>
    <div class="input-container">
        <input type="text" id="user-input" placeholder="Ask about tourism in Morocco...">
        <button onclick="sendMessage()">Send</button>
    </div>

    <script>

        function addMessage(message, isUser) {

            const chatContainer = document.getElementById('chat-container');

            const messageDiv = document.createElement('div');

            messageDiv.className = `message ${isUser ? 'user-message' : 'bot-message'}`;

            messageDiv.textContent = message;

            chatContainer.appendChild(messageDiv);

            chatContainer.scrollTop = chatContainer.scrollHeight;

        }



        function sendMessage() {

            const input = document.getElementById('user-input');

            const message = input.value.trim();

            

            if (message) {

                addMessage(message, true);

                input.value = '';

                document.getElementById('loading').style.display = 'block';

                

                fetch('/chat', {

                    method: 'POST',

                    headers: {

                        'Content-Type': 'application/json',

                    },

                    body: JSON.stringify({ message: message })

                })

                .then(response => response.json())

                .then(data => {

                    document.getElementById('loading').style.display = 'none';

                    addMessage(data.response, false);

                })

                .catch(error => {

                    document.getElementById('loading').style.display = 'none';

                    addMessage('Sorry, an error occurred while processing your message.', false);

                    console.error('Error:', error);

                });

            }

        }



        // Allow sending message with Enter key

        document.getElementById('user-input').addEventListener('keypress', function(e) {

            if (e.key === 'Enter') {

                sendMessage();

            }

        });

    </script>
</body>
</html>