Spaces:
Sleeping
Sleeping
<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> | |