Ashrafb commited on
Commit
c994fc3
·
verified ·
1 Parent(s): 1d48320

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +34 -13
static/index.html CHANGED
@@ -12,32 +12,53 @@
12
  <input type="file" id="image" name="image" accept="image/*"><br>
13
  <label for="question">Question:</label><br>
14
  <input type="text" id="question" name="question"><br>
15
- <button type="submit">Submit</button>
16
  </form>
17
 
18
- <div id="result">
19
  <h2>Result:</h2>
20
  <p id="caption"></p>
21
  </div>
22
 
 
 
 
 
23
  <script>
24
  document.getElementById('uploadForm').addEventListener('submit', async function(event) {
25
  event.preventDefault();
26
-
27
  let formData = new FormData(this);
28
- let response = await fetch('http://localhost:8000/predict/', {
29
- method: 'POST',
30
- body: formData
31
- });
32
-
33
- if (response.ok) {
34
- let result = await response.json();
35
- document.getElementById('caption').innerText = result.result;
36
- document.getElementById('result').style.display = 'block';
37
- } else {
 
 
 
 
 
 
38
  alert('An error occurred while processing the request.');
 
39
  }
40
  });
 
 
 
 
 
 
 
 
 
 
41
  </script>
42
  </body>
43
  </html>
 
12
  <input type="file" id="image" name="image" accept="image/*"><br>
13
  <label for="question">Question:</label><br>
14
  <input type="text" id="question" name="question"><br>
15
+ <button type="submit" id="submitBtn">Submit</button>
16
  </form>
17
 
18
+ <div id="result" style="display: none;">
19
  <h2>Result:</h2>
20
  <p id="caption"></p>
21
  </div>
22
 
23
+ <div id="loading" style="display: none;">
24
+ <p>Loading...</p>
25
+ </div>
26
+
27
  <script>
28
  document.getElementById('uploadForm').addEventListener('submit', async function(event) {
29
  event.preventDefault();
30
+ showLoadingIndicator();
31
  let formData = new FormData(this);
32
+ try {
33
+ let response = await fetch('http://localhost:8000/predict/', {
34
+ method: 'POST',
35
+ body: formData
36
+ });
37
+ if (response.ok) {
38
+ let result = await response.json();
39
+ document.getElementById('caption').innerText = result.result;
40
+ document.getElementById('result').style.display = 'block';
41
+ hideLoadingIndicator();
42
+ } else {
43
+ alert('An error occurred while processing the request.');
44
+ hideLoadingIndicator();
45
+ }
46
+ } catch (error) {
47
+ console.error('An error occurred:', error);
48
  alert('An error occurred while processing the request.');
49
+ hideLoadingIndicator();
50
  }
51
  });
52
+
53
+ function showLoadingIndicator() {
54
+ document.getElementById('loading').style.display = 'block';
55
+ document.getElementById('submitBtn').disabled = true;
56
+ }
57
+
58
+ function hideLoadingIndicator() {
59
+ document.getElementById('loading').style.display = 'none';
60
+ document.getElementById('submitBtn').disabled = false;
61
+ }
62
  </script>
63
  </body>
64
  </html>