Ashrafb commited on
Commit
58746b4
1 Parent(s): 29da619

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +21 -24
static/index.html CHANGED
@@ -6,34 +6,31 @@
6
  <title>Image to Sketch</title>
7
  </head>
8
  <body>
9
- <h1>Upload Image to Get Sketch</h1>
10
- <form id="upload-form" action="/predict" method="post" enctype="multipart/form-data">
11
- <input type="file" name="file" id="file-input">
12
- <button type="submit">Submit</button>
13
  </form>
14
- <div id="result-container"></div>
15
 
16
  <script>
17
- document.getElementById("upload-form").addEventListener("submit", async function(event) {
18
- event.preventDefault();
19
  const formData = new FormData();
20
- formData.append("file", document.getElementById("file-input").files[0]);
21
- try {
22
- const response = await fetch("/predict", {
23
- method: "POST",
24
- body: formData
25
- });
26
- if (!response.ok) {
27
- throw new Error("Failed to get response from server");
28
- }
29
- const data = await response.json();
30
- const sketchImageUrl = data.sketch_image_url;
31
- // Display the sketch image in the result container
32
- document.getElementById("result-container").innerHTML = `<img src="${sketchImageUrl}" alt="Sketch Image">`;
33
- } catch (error) {
34
- console.error("Error:", error);
35
- alert("Failed to process the image. Please try again.");
36
- }
37
  });
38
  </script>
39
  </body>
 
6
  <title>Image to Sketch</title>
7
  </head>
8
  <body>
9
+ <h1>Image to Sketch</h1>
10
+ <form action="/upload/" method="post" enctype="multipart/form-data">
11
+ <input type="file" name="file">
12
+ <button type="submit">Upload</button>
13
  </form>
14
+ <div id="result"></div>
15
 
16
  <script>
17
+ async function uploadFile() {
 
18
  const formData = new FormData();
19
+ const fileInput = document.querySelector('input[type="file"]');
20
+ formData.append('file', fileInput.files[0]);
21
+
22
+ const response = await fetch('/upload/', {
23
+ method: 'POST',
24
+ body: formData
25
+ });
26
+
27
+ const data = await response.json();
28
+ document.getElementById('result').innerHTML = `<img src="data:image/png;base64,${data.sketch_image}" />`;
29
+ }
30
+
31
+ document.querySelector('form').addEventListener('submit', function(event) {
32
+ event.preventDefault();
33
+ uploadFile();
 
 
34
  });
35
  </script>
36
  </body>