Techno Blender
Digitally Yours.

Implement ChatGPT in a Flask Application

0 48


<html>

<head>

    <title>Query</title>

    <script>

        $(document).ready(function() {

            // Send the form on enter keypress and avoid if shift is pressed

            $('#prompt').keypress(function(event) {

                if (event.keyCode === 13 && !event.shiftKey) {

                    event.preventDefault();

                    $('form').submit();

                }

            });

            $('form').on('submit', function(event) {

                event.preventDefault();

            // get the CSRF token from the cookie

            var csrftoken = Cookies.get('csrftoken');

              

            // set the CSRF token in the AJAX headers

            $.ajaxSetup({

                headers: { 'X-CSRFToken': csrftoken }

            });

                // Get the prompt

                var prompt = $('#prompt').val();

                var dateTime = new Date();

                var time = dateTime.toLocaleTimeString();

                // Add the prompt to the response div

                $('#response').append('<p id="GFG1">('+ time + ') <i class="bi bi-person"></i>: ' + prompt + '</p>');

                $('#response #GFG1').css({"color": "green", "width": "90%", "float": "left"});

                // Clear the prompt

                $('#prompt').val('');

                $.ajax({

                    url: '/',

                    type: 'POST',

                    data: {prompt: prompt},

                    dataType: 'json',

                    success: function(data) {

                        $('#response').append('<p id="GFG2">('+ time + ') <i class="bi bi-robot"></i>: ' + data.response + '</p>');

                        $('#response #GFG2').css({"color": "red", "width": "90%", "float": "right"});

                    }

                });

            });

        });

    </script>

</head>

<body>

    <div class="container p-3">

        <h3>GFG ChatGPT Clone</h3>

        <div class="mb-3">

            <form method="post" action="">

                  

                <label for="prompt" class="form-label"><strong>Prompt: </strong></label>

                <textarea class="form-control" type="textarea" id="prompt" name="prompt" rows="3"></textarea>

                <br>

                <button class="btn btn-primary " type="submit">Submit</button>

            </form>

        </div>

        <br>

        <div class="mb-3">

            <h6>Response:</h6

            <div class="container border overflow-auto h-50" id="response"></div>

              

        </div>

    </div>

</body>

</html>


<html>

<head>

    <title>Query</title>

    <script>

        $(document).ready(function() {

            // Send the form on enter keypress and avoid if shift is pressed

            $('#prompt').keypress(function(event) {

                if (event.keyCode === 13 && !event.shiftKey) {

                    event.preventDefault();

                    $('form').submit();

                }

            });

            $('form').on('submit', function(event) {

                event.preventDefault();

            // get the CSRF token from the cookie

            var csrftoken = Cookies.get('csrftoken');

              

            // set the CSRF token in the AJAX headers

            $.ajaxSetup({

                headers: { 'X-CSRFToken': csrftoken }

            });

                // Get the prompt

                var prompt = $('#prompt').val();

                var dateTime = new Date();

                var time = dateTime.toLocaleTimeString();

                // Add the prompt to the response div

                $('#response').append('<p id="GFG1">('+ time + ') <i class="bi bi-person"></i>: ' + prompt + '</p>');

                $('#response #GFG1').css({"color": "green", "width": "90%", "float": "left"});

                // Clear the prompt

                $('#prompt').val('');

                $.ajax({

                    url: '/',

                    type: 'POST',

                    data: {prompt: prompt},

                    dataType: 'json',

                    success: function(data) {

                        $('#response').append('<p id="GFG2">('+ time + ') <i class="bi bi-robot"></i>: ' + data.response + '</p>');

                        $('#response #GFG2').css({"color": "red", "width": "90%", "float": "right"});

                    }

                });

            });

        });

    </script>

</head>

<body>

    <div class="container p-3">

        <h3>GFG ChatGPT Clone</h3>

        <div class="mb-3">

            <form method="post" action="">

                  

                <label for="prompt" class="form-label"><strong>Prompt: </strong></label>

                <textarea class="form-control" type="textarea" id="prompt" name="prompt" rows="3"></textarea>

                <br>

                <button class="btn btn-primary " type="submit">Submit</button>

            </form>

        </div>

        <br>

        <div class="mb-3">

            <h6>Response:</h6

            <div class="container border overflow-auto h-50" id="response"></div>

              

        </div>

    </div>

</body>

</html>

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment