Asanaly commited on
Commit
0b09172
·
verified ·
1 Parent(s): 330f03b

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +9 -25
script.js CHANGED
@@ -1,36 +1,20 @@
1
- // Text summarization
2
- document.getElementById("summarizeTextBtn").onclick = async () => {
3
  const text = document.getElementById("inputText").value;
4
- const lang = document.getElementById("langSelect").value;
5
-
6
- if (!text) {
7
- alert("Please enter text.");
8
- return;
9
- }
10
 
11
  const response = await fetch("/summarize/text", {
12
  method: "POST",
13
  headers: {"Content-Type": "application/json"},
14
- body: JSON.stringify({text: text, lang: lang})
15
  });
16
 
17
  const data = await response.json();
18
- document.getElementById("result").innerText = data.summary || "Error: no summary returned.";
19
- };
20
-
21
- // PDF summarization
22
- document.getElementById("summarizePdfBtn").onclick = async () => {
23
- const fileInput = document.getElementById("pdfFile");
24
- const lang = document.getElementById("pdfLangSelect").value;
25
-
26
- if (!fileInput.files.length) {
27
- alert("Please select a PDF file.");
28
- return;
29
- }
30
 
 
 
31
  const formData = new FormData();
32
- formData.append("file", fileInput.files[0]);
33
- formData.append("lang", lang);
34
 
35
  const response = await fetch("/summarize/pdf", {
36
  method: "POST",
@@ -38,5 +22,5 @@ document.getElementById("summarizePdfBtn").onclick = async () => {
38
  });
39
 
40
  const data = await response.json();
41
- document.getElementById("result").innerText = data.summary || "Error: no summary returned.";
42
- };
 
1
+ async function summarizeText() {
 
2
  const text = document.getElementById("inputText").value;
 
 
 
 
 
 
3
 
4
  const response = await fetch("/summarize/text", {
5
  method: "POST",
6
  headers: {"Content-Type": "application/json"},
7
+ body: JSON.stringify({ text })
8
  });
9
 
10
  const data = await response.json();
11
+ document.getElementById("summaryBox").innerText = data.summary;
12
+ }
 
 
 
 
 
 
 
 
 
 
13
 
14
+ async function summarizePDF() {
15
+ const file = document.getElementById("pdfFile").files[0];
16
  const formData = new FormData();
17
+ formData.append("file", file);
 
18
 
19
  const response = await fetch("/summarize/pdf", {
20
  method: "POST",
 
22
  });
23
 
24
  const data = await response.json();
25
+ document.getElementById("summaryBox").innerText = data.summary;
26
+ }