Spaces:
Sleeping
Sleeping
Amina commited on
Commit ·
c0de9f0
1
Parent(s): e122ef4
changes
Browse files- best.pt +2 -2
- front/index.html +65 -11
best.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:888f7e615513e78b755b66ba3b19b709cc1e0b6cdad9fb368b6b76db8951da29
|
| 3 |
+
size 6256874
|
front/index.html
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<script>
|
| 2 |
-
//
|
| 3 |
-
const API_URL = "https://
|
| 4 |
|
| 5 |
const uploadArea = document.getElementById('upload-area');
|
| 6 |
const imageUpload = document.getElementById('image-upload');
|
|
@@ -53,11 +100,18 @@
|
|
| 53 |
body: formData,
|
| 54 |
});
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
if (!response.ok) {
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
-
const data = await response.json();
|
| 61 |
displayResults(data.conditions);
|
| 62 |
|
| 63 |
} catch (error) {
|
|
@@ -69,21 +123,18 @@
|
|
| 69 |
}
|
| 70 |
});
|
| 71 |
|
| 72 |
-
// --- UPDATED FUNCTION ---
|
| 73 |
-
// This function now correctly handles your new backend messages
|
| 74 |
function displayResults(conditions) {
|
|
|
|
| 75 |
if (!conditions || conditions.length === 0) {
|
| 76 |
-
resultsDiv.innerHTML = "<p>❓ Could not determine condition.</p>";
|
| 77 |
return;
|
| 78 |
}
|
| 79 |
|
| 80 |
-
// Check for the specific "no damage" message
|
| 81 |
if (conditions.length === 1 && conditions[0] === 'No damage detected.') {
|
| 82 |
-
resultsDiv.innerHTML = "<p>✅ No damage detected!</p>";
|
| 83 |
return;
|
| 84 |
}
|
| 85 |
|
| 86 |
-
// Display "Broken", "Dirty", etc.
|
| 87 |
let html = "<h3>Determined Conditions:</h3><ul>";
|
| 88 |
conditions.forEach(condition => {
|
| 89 |
html += `<li><strong>${condition}</strong></li>`;
|
|
@@ -91,4 +142,7 @@
|
|
| 91 |
html += "</ul>";
|
| 92 |
resultsDiv.innerHTML = html;
|
| 93 |
}
|
| 94 |
-
</script>
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Car Damage Detector</title>
|
| 7 |
+
<style>
|
| 8 |
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; text-align: center; margin: 0; background-color: #f0f2f5; }
|
| 9 |
+
.container { max-width: 600px; margin: 50px auto; padding: 30px; background-color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.1); border-radius: 8px; }
|
| 10 |
+
h1 { color: #333; }
|
| 11 |
+
#image-preview { display: none; max-width: 100%; height: auto; margin-top: 20px; border-radius: 4px; border: 1px solid #ddd; }
|
| 12 |
+
.upload-area { border: 2px dashed #007bff; border-radius: 8px; padding: 40px; margin: 20px 0; cursor: pointer; background-color: #f8f9fa; }
|
| 13 |
+
.upload-area p { margin: 0; color: #555; }
|
| 14 |
+
.button-group { display: flex; justify-content: center; gap: 10px; margin-top: 15px; }
|
| 15 |
+
button { font-size: 1.1em; padding: 12px 25px; cursor: pointer; border: none; border-radius: 5px; transition: background-color 0.3s; }
|
| 16 |
+
#check-button { background-color: #007bff; color: white; }
|
| 17 |
+
#check-button:hover { background-color: #0056b3; }
|
| 18 |
+
#check-button:disabled { background-color: #aaa; cursor: not-allowed; }
|
| 19 |
+
#delete-button { background-color: #dc3545; color: white; display: none; }
|
| 20 |
+
#delete-button:hover { background-color: #c82333; }
|
| 21 |
+
#results { margin-top: 30px; font-size: 1.1em; text-align: left; }
|
| 22 |
+
#results ul { list-style-type: none; padding: 0; }
|
| 23 |
+
#results li { background-color: #e9ecef; padding: 10px; margin-bottom: 8px; border-radius: 4px; }
|
| 24 |
+
</style>
|
| 25 |
+
</head>
|
| 26 |
+
<body>
|
| 27 |
+
|
| 28 |
+
<div class="container">
|
| 29 |
+
<h1>🚗 Car Damage Detector</h1>
|
| 30 |
+
<p>Upload a photo to automatically check for scratches, dents, or rust.</p>
|
| 31 |
+
|
| 32 |
+
<div class="upload-area" id="upload-area">
|
| 33 |
+
<p>Click here or drag & drop an image</p>
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
<input type="file" id="image-upload" accept="image/*" hidden>
|
| 37 |
+
|
| 38 |
+
<div class="button-group">
|
| 39 |
+
<button id="check-button" disabled>Check for Damage</button>
|
| 40 |
+
<button id="delete-button">Delete</button>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
<img id="image-preview" src="" alt="Your uploaded image">
|
| 44 |
+
|
| 45 |
+
<div id="results"></div>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
<script>
|
| 49 |
+
// --- FINAL CORRECT URL ---
|
| 50 |
+
const API_URL = "https://amn23-car-image-classification.hf.space/detect";
|
| 51 |
|
| 52 |
const uploadArea = document.getElementById('upload-area');
|
| 53 |
const imageUpload = document.getElementById('image-upload');
|
|
|
|
| 100 |
body: formData,
|
| 101 |
});
|
| 102 |
|
| 103 |
+
const data = await response.json();
|
| 104 |
+
|
| 105 |
+
// This debugging line will show the raw server response in your browser's console
|
| 106 |
+
console.log("Server response:", data);
|
| 107 |
+
|
| 108 |
+
// Check if the response was successful before proceeding
|
| 109 |
if (!response.ok) {
|
| 110 |
+
// Use the error message from the server if it exists, otherwise use a generic one
|
| 111 |
+
const errorMessage = data.detail || response.statusText;
|
| 112 |
+
throw new Error(`Server error: ${errorMessage}`);
|
| 113 |
}
|
| 114 |
|
|
|
|
| 115 |
displayResults(data.conditions);
|
| 116 |
|
| 117 |
} catch (error) {
|
|
|
|
| 123 |
}
|
| 124 |
});
|
| 125 |
|
|
|
|
|
|
|
| 126 |
function displayResults(conditions) {
|
| 127 |
+
// This check is important. If 'conditions' is undefined, the error will be caught.
|
| 128 |
if (!conditions || conditions.length === 0) {
|
| 129 |
+
resultsDiv.innerHTML = "<p>❓ Could not determine condition or no damage found.</p>";
|
| 130 |
return;
|
| 131 |
}
|
| 132 |
|
|
|
|
| 133 |
if (conditions.length === 1 && conditions[0] === 'No damage detected.') {
|
| 134 |
+
resultsDiv.innerHTML = "<p>✅ No damage detected and clean!</p>";
|
| 135 |
return;
|
| 136 |
}
|
| 137 |
|
|
|
|
| 138 |
let html = "<h3>Determined Conditions:</h3><ul>";
|
| 139 |
conditions.forEach(condition => {
|
| 140 |
html += `<li><strong>${condition}</strong></li>`;
|
|
|
|
| 142 |
html += "</ul>";
|
| 143 |
resultsDiv.innerHTML = html;
|
| 144 |
}
|
| 145 |
+
</script>
|
| 146 |
+
|
| 147 |
+
</body>
|
| 148 |
+
</html>
|