Spaces:
Sleeping
Sleeping
mateoluksenberg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -19,16 +19,15 @@ async def classify_image(file: UploadFile = File(...)):
|
|
19 |
result = pipe(image)
|
20 |
|
21 |
# Overall result summary
|
22 |
-
overall_result =
|
23 |
-
|
|
|
24 |
result_with_comment = {
|
25 |
"label": result[0]['label'],
|
26 |
"score": result[0]['score'],
|
27 |
-
"comment": overall_result
|
28 |
}
|
29 |
|
30 |
-
|
31 |
-
return {"classification_result": result_with_comment} # Return the top prediction with comment and overall summary
|
32 |
|
33 |
except Exception as e:
|
34 |
# Handle exceptions, for example: file not found, image format issues, etc.
|
@@ -81,7 +80,7 @@ async def home():
|
|
81 |
button:hover {
|
82 |
background-color: #45a049;
|
83 |
}
|
84 |
-
#result {
|
85 |
margin-top: 20px;
|
86 |
padding: 20px;
|
87 |
background: #fff;
|
@@ -99,6 +98,7 @@ async def home():
|
|
99 |
<button type="submit">Upload</button>
|
100 |
</form>
|
101 |
<div id="result"></div>
|
|
|
102 |
<script>
|
103 |
const form = document.getElementById('upload-form');
|
104 |
form.addEventListener('submit', async (e) => {
|
@@ -115,10 +115,14 @@ async def home():
|
|
115 |
const result = await response.json();
|
116 |
|
117 |
const resultDiv = document.getElementById('result');
|
|
|
|
|
118 |
if (response.ok) {
|
119 |
-
resultDiv.innerHTML = `<h2>Classification Result:</h2><p>${JSON.stringify(result.classification_result)}</p>`;
|
|
|
120 |
} else {
|
121 |
resultDiv.innerHTML = `<h2>Error:</h2><p>${result.detail}</p>`;
|
|
|
122 |
}
|
123 |
});
|
124 |
</script>
|
|
|
19 |
result = pipe(image)
|
20 |
|
21 |
# Overall result summary
|
22 |
+
overall_result = str(result)
|
23 |
+
|
24 |
+
# Add overall result as comment to the top result
|
25 |
result_with_comment = {
|
26 |
"label": result[0]['label'],
|
27 |
"score": result[0]['score'],
|
|
|
28 |
}
|
29 |
|
30 |
+
return {"classification_result": result_with_comment, "overall_result": overall_result} # Return the top prediction with comment and overall summary
|
|
|
31 |
|
32 |
except Exception as e:
|
33 |
# Handle exceptions, for example: file not found, image format issues, etc.
|
|
|
80 |
button:hover {
|
81 |
background-color: #45a049;
|
82 |
}
|
83 |
+
#result, #overall-results {
|
84 |
margin-top: 20px;
|
85 |
padding: 20px;
|
86 |
background: #fff;
|
|
|
98 |
<button type="submit">Upload</button>
|
99 |
</form>
|
100 |
<div id="result"></div>
|
101 |
+
<div id="overall-results"></div>
|
102 |
<script>
|
103 |
const form = document.getElementById('upload-form');
|
104 |
form.addEventListener('submit', async (e) => {
|
|
|
115 |
const result = await response.json();
|
116 |
|
117 |
const resultDiv = document.getElementById('result');
|
118 |
+
const overallResultsDiv = document.getElementById('overall-results');
|
119 |
+
|
120 |
if (response.ok) {
|
121 |
+
resultDiv.innerHTML = `<h2>Top Classification Result:</h2><p>${JSON.stringify(result.classification_result)}</p>`;
|
122 |
+
overallResultsDiv.innerHTML = `<h2>All Results:</h2><p>${result.overall_result}</p>`;
|
123 |
} else {
|
124 |
resultDiv.innerHTML = `<h2>Error:</h2><p>${result.detail}</p>`;
|
125 |
+
overallResultsDiv.innerHTML = '';
|
126 |
}
|
127 |
});
|
128 |
</script>
|