File size: 590 Bytes
662b3c5
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
document.getElementById("upload-form").addEventListener("submit", async (e) => {
    e.preventDefault();
    const fileInput = document.getElementById("file-input");
    const formData = new FormData();
    formData.append("file", fileInput.files[0]);

    const endpoint = fileInput.files[0].type.startsWith("image/") ? "/caption" : "/summarize";
    const response = await fetch(endpoint, {
        method: "POST",
        body: formData
    });
    const result = await response.json();
    document.getElementById("result").innerText = result.summary || result.caption;
});