Asanaly commited on
Commit
3c4672e
·
verified ·
1 Parent(s): a208658

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +15 -33
script.js CHANGED
@@ -1,44 +1,26 @@
1
  async function summarizeText() {
2
  const text = document.getElementById("inputText").value;
3
 
4
- if (!text) {
5
- alert("Please enter text!");
6
- return;
7
- }
 
8
 
9
- try {
10
- const response = await fetch("/summarize/text", {
11
- method: "POST",
12
- headers: { "Content-Type": "application/json" },
13
- body: JSON.stringify({ text })
14
- });
15
- const data = await response.json();
16
- document.getElementById("output").innerText = data.summary;
17
- } catch (err) {
18
- console.error("Error:", err);
19
- document.getElementById("output").innerText = "Error connecting to API";
20
- }
21
  }
22
 
23
  async function summarizePDF() {
24
- const file = document.getElementById("pdfInput").files[0];
25
- if (!file) {
26
- alert("Please upload a PDF file!");
27
- return;
28
- }
29
-
30
  const formData = new FormData();
31
  formData.append("file", file);
32
 
33
- try {
34
- const response = await fetch("/summarize/pdf", {
35
- method: "POST",
36
- body: formData
37
- });
38
- const data = await response.json();
39
- document.getElementById("output").innerText = data.summary;
40
- } catch (err) {
41
- console.error("Error:", err);
42
- document.getElementById("output").innerText = "Error connecting to API";
43
- }
44
  }
 
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",
21
+ body: formData
22
+ });
23
+
24
+ const data = await response.json();
25
+ document.getElementById("summaryBox").innerText = data.summary;
 
 
 
 
26
  }