| <html> | |
| <head> | |
| <title>KTH Q&A</title> | |
| <link href="{{ url_for('static', path='/styles.css') }}" rel="stylesheet"> | |
| <style> | |
| @import "https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700"; | |
| body { | |
| font-family: 'Poppins', sans-serif; | |
| background: #fafafa; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| margin-left: 20%; | |
| margin-right: 20%; | |
| } | |
| * { | |
| font-family: 'Poppins', sans-serif; | |
| } | |
| .container { | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| justify-content: center; | |
| justify-items: center; | |
| margin-top: 5%; | |
| margin-bottom: 5%; | |
| width: 100%; | |
| } | |
| h1 { | |
| margin-top: 0; | |
| font-size: 3em; | |
| text-align: center; | |
| color: blue; | |
| margin-bottom: auto; | |
| } | |
| h2 { | |
| font-size: 1em; | |
| text-align: center; | |
| color: grey; | |
| margin-bottom: 2em; | |
| } | |
| form { | |
| display: flex; | |
| flex-direction: row; | |
| margin-top: auto; | |
| font-family: 'Poppins', sans-serif; | |
| } | |
| button { | |
| margin: 0.5em; | |
| padding: 0.5em; | |
| background-color: blue; | |
| color: white; | |
| border: none; | |
| border-radius: 0.5em; | |
| padding-left: 1em; | |
| padding-right: 1em; | |
| font-size: 1.1em; | |
| font-weight: 300; | |
| line-height: 1.7em; | |
| transition: all 0.3s; | |
| cursor: pointer; | |
| align-self: self-end; | |
| } | |
| button:disabled { | |
| background-color: #ccc; | |
| color: #666; | |
| cursor: not-allowed; | |
| } | |
| button:hover { | |
| background-color: #ace; | |
| color: #fff; | |
| } | |
| input { | |
| margin: 0.5em; | |
| padding: 0.5em; | |
| width: 35em; | |
| } | |
| p { | |
| font-size: 1.1em; | |
| font-weight: 300; | |
| line-height: 1.7em; | |
| color: #999; | |
| max-width: 30em; | |
| } | |
| a { | |
| color: blue; | |
| text-decoration: none; | |
| transition: all 0.3s; | |
| } | |
| a:hover, | |
| a:focus { | |
| color: cornflowerblue; | |
| text-decoration: none; | |
| transition: all 0.3s; | |
| } | |
| #content { | |
| width: 100%; | |
| padding: 20px; | |
| min-height: 100vh; | |
| transition: all 0.3s; | |
| position: absolute; | |
| top: 0; | |
| right: 0; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>KTH Q&A</h1> | |
| <h2>Your digital Study Counsellor</h2> | |
| <form name="form" method="post"> | |
| <input type="text" name="question" /> | |
| <button type="submit" id="ask">Ask</button> | |
| </form> | |
| <p id="answer"></p> | |
| <p id="readmore"></p> | |
| <ul id="urls"></ul> | |
| </div> | |
| <script> | |
| const form = document.querySelector('form'); | |
| form.addEventListener('submit', async (event) => { | |
| document.getElementById('ask').disabled = true; | |
| event.preventDefault(); | |
| const formData = new FormData(form); | |
| const question = formData.get('question'); | |
| const response = await fetch('/api/ask', { | |
| method: 'POST', | |
| body: JSON.stringify({ question }), | |
| headers: { | |
| 'content-type': 'application/json' | |
| } | |
| }); | |
| const data = await response.json(); | |
| console.log(data); | |
| document.querySelector('#answer').textContent = data.answer; | |
| if (data.urls && data.urls.length > 0) { | |
| document.getElementById('readmore').textContent = 'You might find related info at: '; | |
| const urls = document.getElementById('urls'); | |
| urls.innerHTML = ''; | |
| data.urls.forEach(url => { | |
| const li = document.createElement('li'); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.textContent = url; | |
| li.appendChild(a); | |
| urls.appendChild(li); | |
| }); | |
| } else { | |
| document.getElementById('readmore').textContent = ''; | |
| document.getElementById('urls').innerHTML = ''; | |
| } | |
| document.getElementById('ask').disabled = false; | |
| }); | |
| </script> | |
| {% if DEBUG %} | |
| {{ hotreload.script(url_for('hot-reload')) | safe }} | |
| {% endif %} | |
| </body> | |
| </html> |