Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0613· OpenAIHugging Face Arena Human Preference 55K

Write complete functioning code for a simple web app with input field and submit button…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmixtral-8x7b-instruct-v0.1’s answer.
  1. User

    Write complete functioning code for a simple web app with input field and submit button using HTML, Flask, HTMX and modern styling with Tailwind css

  2. Assistant

    Sure, here's a simple web application using HTML, Flask, HTMX and Tailwind CSS. This application will take input from an input field and return the same text to the user when they press the 'Submit' button.

    Firstly, you need to ensure you have Flask and Tailwind installed. If not, you can install them via pip:

    pip install flask
    

    For Tailwind CSS, you can follow installation guide from the official website.

    Here is the Python script using Flask:

    # app.py
    from flask import Flask, render_template, request
    
    app = Flask(__name__)
    
    @app.route('/', methods=['GET', 'POST'])
    def home():
        message = ''
        if request.method == 'POST':
            message = request.form.get('message')
        return render_template('index.html', message=message)
    
    if __name__ == '__main__':
        app.run(debug=True)
    

    Here is the HTML file using Tailwind CSS for styling and HTMX for AJAX requests:

    <!-- templates/index.html -->
    <!DOCTYPE html>
    <html>
    <head>
        <title>Simple Web App</title>
        <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.16/dist/tailwind.min.css" rel="stylesheet">
    </head>
    <body class="p-5">
        <div class="max-w-md mx-auto bg-white p-5 rounded-md shadow-sm">
            <form method="POST" hx-post="/" hx-swap="outerHTML">
                <div class="mb-4">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="message">
                        Enter Message:
                    </label>
                    <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="message" type="text" name="message">
                </div>
                <div class="flex items-center justify-between">
                    <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" type="submit">
                        Submit
                    </button>
                </div>
            </form>
            {% if message %}
            <div class="mt-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-4" role="alert">
                <p class="font-bold">Message</p>
                <p>{{ message }}</p>
            </div>
            {% endif %}
        </div>
    </body>
    <script src="https://unpkg.com/htmx.org@1.6.1"></script>
    </html>
    

    To run the application, you can use the command python app.py and then open your web browser and go to http://127.0.0.1:5000/.

    Please note that this web app is very basic and doesn't validate user inputs, handle errors, or secure against attacks. When building a real web app, you'll need to consider these factors.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.