|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
| 6 | + <title>NLP Question Answering</title> |
| 7 | + <script src="https://cdn.tailwindcss.com"></script> |
| 8 | + <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet" /> |
| 9 | + <style> |
| 10 | + body { |
| 11 | + font-family: 'Inter', sans-serif; |
| 12 | + } |
| 13 | + </style> |
| 14 | +</head> |
| 15 | +<body class="bg-gradient-to-br from-blue-100 via-purple-100 to-pink-100 min-h-screen flex flex-col"> |
| 16 | + <!-- Header --> |
| 17 | + <header class="bg-white shadow-md sticky top-0 z-10"> |
| 18 | + <div class="max-w-7xl mx-auto px-6 py-4 flex justify-between items-center"> |
| 19 | + <h1 class="text-2xl font-bold text-purple-600">Playing with Natural Language Processing</h1> |
| 20 | + </div> |
| 21 | + </header> |
| 22 | + |
| 23 | + <!-- Main Section --> |
| 24 | + <main class="flex-grow px-4 py-16"> |
| 25 | + <!-- Hero --> |
| 26 | + <section class="text-center mb-12"> |
| 27 | + <h2 class="text-4xl md:text-5xl font-extrabold text-gray-800 mb-4"> |
| 28 | + Question Answering |
| 29 | + </h2> |
| 30 | + <p class="text-lg text-gray-600 max-w-2xl mx-auto"> |
| 31 | + Get your answers for Who, What, When, Where, How much etc. |
| 32 | + </p> |
| 33 | + </section> |
| 34 | + |
| 35 | + <!-- Form --> |
| 36 | + <section class="max-w-xl mx-auto bg-white p-8 rounded-xl shadow-lg mb-8"> |
| 37 | + <form id="qaForm" class="space-y-6"> |
| 38 | + <div> |
| 39 | + <label class="block text-gray-700 font-medium mb-1" for="textInput">Text</label> |
| 40 | + <input type="text" id="textInput" name="text" placeholder="Enter your sentence" |
| 41 | + class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500" required /> |
| 42 | + </div> |
| 43 | + <div> |
| 44 | + <label class="block text-gray-700 font-medium mb-1" for="questionInput">Question</label> |
| 45 | + <input type="text" id="questionInput" name="question" placeholder="Enter your question" |
| 46 | + class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500" required /> |
| 47 | + </div> |
| 48 | + <button type="submit" |
| 49 | + class="w-full bg-purple-600 hover:bg-purple-700 text-white font-semibold py-3 rounded-lg transition"> |
| 50 | + Submit |
| 51 | + </button> |
| 52 | + </form> |
| 53 | + </section> |
| 54 | + |
| 55 | + <!-- Answer Section --> |
| 56 | + <section id="answerSection" class="max-w-xl mx-auto hidden"> |
| 57 | + <div class="bg-white p-6 rounded-lg shadow-lg border-l-8 border-purple-500"> |
| 58 | + <h4 class="text-lg font-semibold text-purple-700 mb-2">Answer:</h4> |
| 59 | + <p id="answerText" class="text-gray-800 text-xl font-medium"></p> |
| 60 | + </div> |
| 61 | + </section> |
| 62 | + |
| 63 | + <!-- Examples Section --> |
| 64 | + <section class="max-w-3xl mx-auto mt-20"> |
| 65 | + <h3 class="text-2xl font-bold text-gray-800 mb-6">Examples</h3> |
| 66 | + |
| 67 | + <div class="bg-white p-6 rounded-lg shadow mb-6"> |
| 68 | + <p class="mb-2"><strong class="text-purple-600">Text:</strong> Apaar went to school.</p> |
| 69 | + <p class="mb-1"><strong class="text-gray-700">Question:</strong> Who went to school?</p> |
| 70 | + </div> |
| 71 | + |
| 72 | + <div class="bg-white p-6 rounded-lg shadow mb-6"> |
| 73 | + <p class="mb-2"><strong class="text-purple-600">Text:</strong> The book was read by Akshar.</p> |
| 74 | + <p><strong class="text-gray-700">Other question:</strong> What was read?</p> |
| 75 | + </div> |
| 76 | + |
| 77 | + <div class="bg-white p-6 rounded-lg shadow mb-6"> |
| 78 | + <p class="mb-2"><strong class="text-purple-600">Text:</strong> My birthday is on 22nd January.</p> |
| 79 | + <p class="mb-1"><strong class="text-gray-700">Question:</strong> When is my birthday?</p> |
| 80 | + </div> |
| 81 | + |
| 82 | + <div class="bg-white p-6 rounded-lg shadow mb-6"> |
| 83 | + <p class="mb-2"><strong class="text-purple-600">Text:</strong> We visited Colombo for a vacation.</p> |
| 84 | + <p class="mb-1"><strong class="text-gray-700">Question:</strong> Where did you go?</p> |
| 85 | + </div> |
| 86 | + |
| 87 | + <div class="bg-white p-6 rounded-lg shadow mb-6"> |
| 88 | + <p class="mb-2"><strong class="text-purple-600">Text:</strong> The eggs cost Rs 20.</p> |
| 89 | + <p class="mb-1"><strong class="text-gray-700">Question:</strong> How much did it cost?</p> |
| 90 | + </div> |
| 91 | + </section> |
| 92 | + </main> |
| 93 | + |
| 94 | + <!-- Footer --> |
| 95 | + <footer class="bg-white text-center text-gray-500 text-sm py-6 shadow-inner mt-12"> |
| 96 | + © Akshar Raaj |
| 97 | + </footer> |
| 98 | + |
| 99 | + <!-- JS --> |
| 100 | + <script> |
| 101 | + const form = document.getElementById('qaForm'); |
| 102 | + const answerSection = document.getElementById('answerSection'); |
| 103 | + const answerText = document.getElementById('answerText'); |
| 104 | + |
| 105 | + form.addEventListener('submit', async (e) => { |
| 106 | + e.preventDefault(); |
| 107 | + |
| 108 | + const text = document.getElementById('textInput').value.trim(); |
| 109 | + const question = document.getElementById('questionInput').value.trim(); |
| 110 | + |
| 111 | + try { |
| 112 | + const response = await fetch('http://localhost:8000/converse', { |
| 113 | + method: 'POST', |
| 114 | + headers: { |
| 115 | + 'Content-Type': 'application/json' |
| 116 | + }, |
| 117 | + body: JSON.stringify({ text, question }) |
| 118 | + }); |
| 119 | + |
| 120 | + if (!response.ok) { |
| 121 | + throw new Error('Failed to fetch answer.'); |
| 122 | + } |
| 123 | + |
| 124 | + const data = await response.json(); |
| 125 | + answerText.textContent = data.answer || 'No answer returned.'; |
| 126 | + answerSection.classList.remove('hidden'); |
| 127 | + } catch (error) { |
| 128 | + answerText.textContent = 'An error occurred. Please try again.'; |
| 129 | + answerSection.classList.remove('hidden'); |
| 130 | + } |
| 131 | + }); |
| 132 | + </script> |
| 133 | +</body> |
| 134 | +</html> |
0 commit comments