from flask import Flask, render_template, request, jsonify
import requests

app = Flask(__name)

# Replace with your Edamam API credentials
APP_ID = '9d5f6314'
APP_KEY = '6402f0a5647c2c2bb72cb3bb592d0c8b'

@app.route('/')
def index():
    return '''
    <!DOCTYPE html>
    <html>
    <head>
        <style>
            /* Stylish CSS for the search bar */
            body {
                font-family: Arial, sans-serif;
                text-align: center;
                background-color: #f5f5f5;
            }

            #search-container {
                display: flex;
                flex-direction: column;
                align-items: center;
                margin: 50px;
            }

            #search-bar {
                width: 300px;
                padding: 10px;
                font-size: 18px;
                border: none;
                border-radius: 5px;
                box-shadow: 0px 0px 5px 2px #888888;
            }

            #search-bar::placeholder {
                color: #888888;
            }

            #search-button {
                margin-top: 10px;
                padding: 10px 20px;
                background-color: #007BFF;
                color: #fff;
                border: none;
                border-radius: 5px;
                cursor: pointer;
                transition: background-color 0.3s;
            }

            #search-button:hover {
                background-color: #0056b3;
            }

            #results {
                text-align: left;
                margin: 20px;
            }
        </style>
    </head>
    <body>
        <h1>Recipe Search</h1>

        <div id="search-container">
            <input type="text" id="search-bar" placeholder="Search for recipes...">
            <button id="search-button">Search</button>
        </div>
        
        <div id="results"></div>

        <script>
            const searchInput = document.getElementById('search-bar');
            const searchButton = document.getElementById('search-button');
            const resultsDiv = document.getElementById('results');

            function performSearch(query) {
                // Replace this with your search logic or API request
                resultsDiv.innerHTML = `<p>Searching for: ${query}</p>`;
            }

            // Event listener for clicking the "Search" button
            searchButton.addEventListener('click', function() {
                const query = searchInput.value;
                performSearch(query);
            });

            // Event listener for the Enter key
            searchInput.addEventListener('keyup', function(event) {
                if (event.key === 'Enter') {
                    const query = searchInput.value;
                    performSearch(query);
                }
            });
        </script>
    </body>
    </html>
    '''

@app.route('/search', methods=['GET'])
def search():
    query = request.args.get('query')

    # Make the API request
    api_endpoint = 'https://api.edamam.com/search'
    params = {
        'q': query,
        'app_id': APP_ID,
        'app_key': APP_KEY,
    }

    response = requests.get(api_endpoint, params=params)

    if response.status_code == 200:
        data = response.json()
        return jsonify(data)
    else:
        return jsonify({"error": "API request failed"})

if __name__ == '__main__':
    app.run()

---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

Cell In[1], line 4
      1 from flask import Flask, render_template, request, jsonify
      2 import requests
----> 4 app = Flask(__name)
      6 # Replace with your Edamam API credentials
      7 APP_ID = '9d5f6314'


NameError: name '__name' is not defined