File size: 2,688 Bytes
2edba59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Recipe Generator</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .container {
            text-align: center;
        }
        h1 {
            margin-bottom: 20px;
        }
        input[type="text"] {
            padding: 10px;
            margin-bottom: 20px;
            width: 300px;
            font-size: 16px;
            border-radius: 5px;
            border: 1px solid #ccc;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        #recipe {
            margin-top: 20px;
            text-align: left; /* Align recipe text to the left */
            white-space: pre-line; /* New line */
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Recipe Generator</h1>
        <p>Please provide a list of your available ingredients, separated by a comma</p>
        <form id="ingredientsForm">
            <input type="text" id="ingredientsInput" placeholder="Enter ingredients (comma-separated)" required>
            <button type="submit">Generate Recipe</button>
        </form>
        <div id="recipe"></div>
    </div>

    <script>
        document.getElementById('ingredientsForm').addEventListener('submit', function(event) {
            event.preventDefault();
            var ingredients = document.getElementById('ingredientsInput').value.trim();
            if (ingredients) {
                fetch('/recipe', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: 'ingredients=' + encodeURIComponent(ingredients),
                })
                .then(response => response.text())
                .then(recipe => {
                    document.getElementById('recipe').innerHTML = recipe;
                })
                .catch(error => console.error('Error:', error));
            } else {
                alert('Please enter at least one ingredient.');
            }
        });
    </script>
</body>
</html>