-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (44 loc) · 2.15 KB
/
script.js
File metadata and controls
60 lines (44 loc) · 2.15 KB
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
// نظرات تستی - در صورت نیاز از API یا فایل JSON بارگذاری کن
const comments = [
{ author: "Mohammad", text: "The build quality is excellent and the packaging was very nice." },
{ author: "Sarah", text: "I am very satisfied with my purchase, especially the stylish design." },
{ author: "Ali", text: "It arrived on time and the quality exceeded my expectations." },
{ author: "Bardia", text: "Very good, especially the delicate design and neat packaging." },
{ author: "Mina", text: "Worth the price, I had a good experience." },
{ author: "Mehdi", text: "Good appearance, good performance, everything is great." },
{ author: "Narges", text: "I ordered two and both arrived intact." },
{ author: "Reza", text: "The price is a bit high but the quality makes up for it." },
{ author: "Elham", text: "The battery drains quickly, I expected more." }, // negative
{ author: "Saman", text: "The delivery was late and customer support was unresponsive." } // negative
];
const container = document.getElementById("comments-container");
comments.forEach(comment => {
const div = document.createElement("div");
div.className = "comment-box";
div.innerHTML = `
<div class="comment-author">${comment.author}</div>
<div class="comment-text">${comment.text}</div>
`;
container.appendChild(div);
});
// type yor token here
const token = "ُType your token here";
window.addEventListener('load', () => summarizeComments());
async function summarizeComments() {
const fullText = comments.map(c => c.text).join(". ");
// مرحله 2: درخواست به Hugging Face API
// type your api link here
const response = await fetch("Type Your Api Here", {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ inputs: fullText })
});
const data = await response.json();
const summary = data[0]?.summary_text || "نتونست خلاصه کنه.";
// مرحله 3: نمایش نتیجه در صفحه
document.getElementById("summary-box").innerText = `Ai Summary : ${summary}`;
console.log("Raw response:", data);
}