-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (41 loc) · 1.54 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Article Generator</title>
</head>
<body>
<h1>Article Generator</h1>
<div id="article-form">
<label for="prompt">Enter a prompt:</label>
<textarea id="prompt" rows="4" cols="50"></textarea>
<br>
<button onclick="generateArticle()">Generate Article</button>
</div>
<div id="result">
<!-- Display generated content here -->
</div>
<script>
function generateArticle() {
var prompt = document.getElementById('prompt').value;
// Make an AJAX request to the server
var xhr = new XMLHttpRequest();
xhr.open('POST', '/generate_article', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
displayResult(response.prompt, response.article);
}
};
xhr.send('prompt=' + encodeURIComponent(prompt));
}
function displayResult(prompt, article) {
var resultDiv = document.getElementById('result');
resultDiv.innerHTML = '<h2>Your Prompt:</h2><p>' + prompt + '</p>' +
'<h2>Generated Article:</h2><p>' + article + '</p>';
}
</script>
</body>
</html>