File size: 3,207 Bytes
3f4d0b1
 
 
 
 
a6ca086
3f4d0b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6ca086
3f4d0b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3492cf8
3f4d0b1
 
 
 
 
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
$(document).ready(function(){
    $('#uploadForm').on('submit', function(e){
        e.preventDefault();
        $('#uploadStatus').html('<p>Status: Processing...</p>');
        $.ajax({
            url: "/upload",
            type: 'POST',
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
            success: function(response){
                $('#uploadStatus').html('<p>Status: '+response.status+'</p>');
            }
        });
    });
});


(function () {
    var Message;
    Message = function (arg) {
        this.text = arg.text, this.message_side = arg.message_side;
        this.draw = function (_this) {
            return function () {
                var $message;
                $message = $($('.message_template').clone().html());
                $message.addClass(_this.message_side === 'user' ? 'user-message' : 'bot-message')
                        .find('.text').html(_this.text);
                $('.messages').append($message);
                return setTimeout(function () {
                    return $message.addClass('appeared');
                }, 0);
            };
        }(this);
        return this;
    };

    $(function () {
        var getMessageText, sendMessage;
        getMessageText = function () {
            var $message_input;
            $message_input = $('.message_input');
            return $message_input.val();
        };

        sendMessage = function (text) {
            var $messages, message;
            if (text.trim() === '') {
                return;
            }
            $('.message_input').val('');
            $messages = $('.messages');

            // Set message_side based on whether the message is from the user or chatbot
            var userMessageSide = 'user';
            var botMessageSide = 'bot';

            // Draw user message with user-message class
            message = new Message({
                text: text,
                message_side: userMessageSide
            });
            message.draw();

            // Call getResponse() to get the chatbot's response
            $.get("/get", { msg: text }).done(function(data) {
                // Draw bot message with bot-message class
                var botMessage = new Message({
                    text: data,
                    message_side: botMessageSide
                });
                botMessage.draw();
                $messages.animate({ scrollTop: $messages.prop('scrollHeight') }, 300);
            });

            return $messages.animate({ scrollTop: $messages.prop('scrollHeight') }, 300);
        };

        $('.send_message').click(function (e) {
            return sendMessage(getMessageText());
        });
        $('.message_input').keyup(function (e) {
            if (e.which === 13) {
                return sendMessage(getMessageText());
            }
        });

        // Add initial bot message
        var initialBotMessage = new Message({
            text: 'চালিয়ে যেতে একটি ছবি আপলোড করুন',
            message_side: 'bot'
        });
        initialBotMessage.draw();
    });
})();