Spaces:
Sleeping
Sleeping
cyberai-1 commited on
Commit ·
52cb39a
1
Parent(s): 85535f1
Improve confidence percentage display
Browse files- app.py +8 -1
- templates/dashboard.html +1 -1
- templates/predict.html +2 -2
app.py
CHANGED
|
@@ -258,9 +258,16 @@ def predict_sign(path):
|
|
| 258 |
return label, confidence
|
| 259 |
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
@app.context_processor
|
| 262 |
def inject_user():
|
| 263 |
-
return {"user": current_user()}
|
| 264 |
|
| 265 |
|
| 266 |
@app.route("/")
|
|
|
|
| 258 |
return label, confidence
|
| 259 |
|
| 260 |
|
| 261 |
+
def format_confidence(confidence):
|
| 262 |
+
value = max(0.0, min(float(confidence or 0), 1.0)) * 100
|
| 263 |
+
if 99.995 <= value < 100:
|
| 264 |
+
value = 99.99
|
| 265 |
+
return f"{value:.2f}%"
|
| 266 |
+
|
| 267 |
+
|
| 268 |
@app.context_processor
|
| 269 |
def inject_user():
|
| 270 |
+
return {"format_confidence": format_confidence, "user": current_user()}
|
| 271 |
|
| 272 |
|
| 273 |
@app.route("/")
|
templates/dashboard.html
CHANGED
|
@@ -80,7 +80,7 @@
|
|
| 80 |
<tr>
|
| 81 |
<td><img class="thumb" src="{{ url_for('static', filename=row.image_path) }}" alt="Traffic sign"></td>
|
| 82 |
<td>{{ row.predicted_class }}</td>
|
| 83 |
-
<td>{{
|
| 84 |
<td>
|
| 85 |
{% if row.is_correct == 1 %}
|
| 86 |
<span class="status true">True</span>
|
|
|
|
| 80 |
<tr>
|
| 81 |
<td><img class="thumb" src="{{ url_for('static', filename=row.image_path) }}" alt="Traffic sign"></td>
|
| 82 |
<td>{{ row.predicted_class }}</td>
|
| 83 |
+
<td>{{ format_confidence(row.confidence) }}</td>
|
| 84 |
<td>
|
| 85 |
{% if row.is_correct == 1 %}
|
| 86 |
<span class="status true">True</span>
|
templates/predict.html
CHANGED
|
@@ -47,7 +47,7 @@
|
|
| 47 |
<div class="prediction-result">
|
| 48 |
<span>Predicted class</span>
|
| 49 |
<strong>{{ prediction.predicted_class }}</strong>
|
| 50 |
-
<small>Confidence: {{
|
| 51 |
</div>
|
| 52 |
<form class="feedback-row" method="post" action="{{ url_for('feedback', prediction_id=prediction.id) }}">
|
| 53 |
<input type="hidden" name="next" value="{{ url_for('predict') }}">
|
|
@@ -72,7 +72,7 @@
|
|
| 72 |
<article class="history-card">
|
| 73 |
<img src="{{ url_for('static', filename=row.image_path) }}" alt="Traffic sign prediction">
|
| 74 |
<strong>{{ row.predicted_class }}</strong>
|
| 75 |
-
<small>{{
|
| 76 |
</article>
|
| 77 |
{% else %}
|
| 78 |
<p class="empty">No predictions yet.</p>
|
|
|
|
| 47 |
<div class="prediction-result">
|
| 48 |
<span>Predicted class</span>
|
| 49 |
<strong>{{ prediction.predicted_class }}</strong>
|
| 50 |
+
<small>Confidence: {{ format_confidence(prediction.confidence) }}</small>
|
| 51 |
</div>
|
| 52 |
<form class="feedback-row" method="post" action="{{ url_for('feedback', prediction_id=prediction.id) }}">
|
| 53 |
<input type="hidden" name="next" value="{{ url_for('predict') }}">
|
|
|
|
| 72 |
<article class="history-card">
|
| 73 |
<img src="{{ url_for('static', filename=row.image_path) }}" alt="Traffic sign prediction">
|
| 74 |
<strong>{{ row.predicted_class }}</strong>
|
| 75 |
+
<small>{{ format_confidence(row.confidence) }} confidence</small>
|
| 76 |
</article>
|
| 77 |
{% else %}
|
| 78 |
<p class="empty">No predictions yet.</p>
|