ayazfau's picture
Update templates/index.html
1b6af4a verified
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat UI</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body class="bg-light">
<div class="container py-4">
<h1 class="mb-4">Chat UI</h1>
<form id="chatForm">
<div class="mb-3">
<label for="userInput" class="form-label">User Input:</label>
<input type="text" id="userInput" class="form-control" name="text" required>
</div>
<button type="submit" class="btn btn-primary">Generate Response</button>
</form>
<div id="output" class="mt-4">
<h2>Output:</h2>
<p id="response" class="text-muted">Waiting for response...</p>
</div>
</div>
<!-- Bootstrap JS (optional, for components like modals) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-I5qk7Sre1gBaw0r+UVjz5VewS9D90t+7fJAkfxB8zbabFegBl1XjcFEx5anftvb7" crossorigin="anonymous"></script>
<script>
async function generateResponse() {
const userInput = document.getElementById("userInput").value;
const responseElement = document.getElementById("response");
const response = await fetch(`/generate?text=${encodeURIComponent(userInput)}`);
const responseData = await response.json();
responseElement.textContent = responseData.output;
}
const chatForm = document.getElementById("chatForm");
chatForm.addEventListener("submit", function(event) {
event.preventDefault();
generateResponse();
});
</script>
</body>
</html>