-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
103 lines (92 loc) · 3.07 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: sans-serif;
}
.hashtag-container {
display: flex;
flex-direction: column;
width: 50%; /* Occupy half the screen width */
max-width: 400px; /* Limit maximum width */
border: 1px solid #ccc;
border-radius: 5px;
}
.hastag-messages {
padding: 10px;
height: 100px;
overflow-y: auto;
}
.hastag-input {
display: flex;
padding: 10px;
}
.hashtag-input textarea {
flex-grow: 1;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
resize: vertical;
height: 100px;
}
.hastag-input button {
padding: 8px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="hashtag-container">
<div id="hashtag-messages" class="hashtag-messages">
</div>
<div class="hashtag-input">
<textarea id="hashtag-input" placeholder="Enter your text here..."></textarea>
<button onclick="generateHashtags()">Generate Hashtags</button>
<button onclick="clearOutput()">Clear</button>
</div>
</div>
<script>
let aiSession = null;
async function initTextSession() {
if (!window.ai) {
throw new Error("Chrome AI API is not available.");
}
aiSession = await ai.languageModel.create();
console.log("AI Session created.");
}
function addMessage(message) {
document.getElementById("hashtag-messages").innerHTML = message; // Update the entire content
}
async function generateHashtags() {
const textInput = document.getElementById("hashtag-input");
const text = textInput.value.trim();
if (!text) return;
if (!aiSession) {
addMessage("AI: Sorry I am not available now.");
return;
}
const response = await aiSession.prompt(`This is the content of an article: ${text} Summarize in three basic hashtag with emojis at the end of each hashtag! Please make sure you only write the hashtags and emojis down, nothing more!`);
addMessage("Summary: " + response);
}
function clearOutput() {
document.getElementById("hashtag-input").value = "";
document.getElementById("hashtag-messages").innerHTML = "";
}
initTextSession();
</script>
</body>
</html>