Advay-Singh commited on
Commit
883cb50
·
verified ·
1 Parent(s): a8d02b0

Update templates/summarize.html

Browse files
Files changed (1) hide show
  1. templates/summarize.html +21 -15
templates/summarize.html CHANGED
@@ -47,7 +47,7 @@
47
 
48
  <textarea name="question" id="question" placeholder="Write your text here to summarize..."></textarea><br><br><br>
49
 
50
- <button onclick=answer()>Start Summarizing</button>
51
  <label for="type">Summarize to: </label>
52
  <select name="type" id="type">
53
  <option value="points">Points</option>
@@ -59,27 +59,33 @@
59
  <textarea name="answer" id="answer" placeholder="Summary will be displayed here..."></textarea>
60
  <script>
61
  async function answer() {
 
62
  const userInput = document.getElementById('question').value;
63
  if (userInput.trim() === '') return;
64
  const question = userInput;
65
  const type = document.getElementById("type").value;
66
  const num_of_lines_points = document.getElementById("lines_points").value;
67
- const response = await fetch("/summarize", {
68
- method: "POST",
69
- headers: {
70
- "Content-Type": "application/x-www-form-urlencoded"
71
- },
72
- body: new URLSearchParams({ question: question, type: type, num_of_lines_points: num_of_lines_points })
73
- });
74
- const data = await response.json();
75
- const answer_area = document.getElementById("answer");
76
- if (data.answer) {
77
- aiResponse = data.answer;
78
- answer_area.value = aiResponse
79
- } else if (data.error) {
80
- aiResponse = "Error: " + data.error;
 
81
  answer_area.value = aiResponse
 
 
 
82
  }
 
83
  }
84
  </script>
85
  </body>
 
47
 
48
  <textarea name="question" id="question" placeholder="Write your text here to summarize..."></textarea><br><br><br>
49
 
50
+ <button onclick=answer() id="answer_button">Start Summarizing</button>
51
  <label for="type">Summarize to: </label>
52
  <select name="type" id="type">
53
  <option value="points">Points</option>
 
59
  <textarea name="answer" id="answer" placeholder="Summary will be displayed here..."></textarea>
60
  <script>
61
  async function answer() {
62
+ document.getElementById("answer_button").disabled = true
63
  const userInput = document.getElementById('question').value;
64
  if (userInput.trim() === '') return;
65
  const question = userInput;
66
  const type = document.getElementById("type").value;
67
  const num_of_lines_points = document.getElementById("lines_points").value;
68
+ try {
69
+ const response = await fetch("/summarize", {
70
+ method: "POST",
71
+ headers: {
72
+ "Content-Type": "application/x-www-form-urlencoded"
73
+ },
74
+ body: new URLSearchParams({ question: question, type: type, num_of_lines_points: num_of_lines_points })
75
+ });
76
+ const data = await response.json();
77
+ const answer_area = document.getElementById("answer");
78
+ if (data.answer) {
79
+ aiResponse = data.answer;
80
+ } else if (data.error) {
81
+ aiResponse = "Error: " + data.error;
82
+ }
83
  answer_area.value = aiResponse
84
+ } catch (err) {
85
+ console.error("Fetch Error:", err);
86
+ document.getElementById("answer").value = err;
87
  }
88
+ document.getElementById("answer_button").disabled = false
89
  }
90
  </script>
91
  </body>