Spaces:
Sleeping
Sleeping
Gabriel Henrique commited on
Commit ·
7983a21
1
Parent(s): f2ca694
merge: resolver conflito e incorporar atualizacoes do Hugging Face
Browse files- app.py +117 -41
- templates/index.html +36 -0
- templates/resultados_artigo.html +79 -0
app.py
CHANGED
|
@@ -32,6 +32,9 @@ os.environ["CORE_MODEL_YOLO_WORLD_ENABLED"] = "False"
|
|
| 32 |
|
| 33 |
app = Flask(__name__)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
# --- CONFIGURAÇÕES INICIAIS ---
|
| 36 |
# A chave da API do Roboflow agora é carregada automaticamente do arquivo .env
|
| 37 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -65,48 +68,25 @@ def get_text_features(model, text_descriptions: Dict[str, str], device="cpu"):
|
|
| 65 |
# --- DICIONÁRIO DE DESCRIÇÕES OTIMIZADO PARA LONGCLIP ---
|
| 66 |
text_descriptions_longclip = {
|
| 67 |
"Mancha de Olho Pardo (Cercospora)": (
|
| 68 |
-
"A
|
| 69 |
-
"The
|
| 70 |
-
"This
|
| 71 |
-
"
|
| 72 |
-
"The spot surface is perfectly flat and dry. "
|
| 73 |
-
"Crucially, it completely lacks any raised orange powder or granular dust. "
|
| 74 |
-
"There is also absolutely no pitch-black color in the lesion; it is only dark brown, never black."
|
| 75 |
),
|
| 76 |
-
|
| 77 |
"Ferrugem do Cafeeiro": (
|
| 78 |
-
"A highly
|
| 79 |
-
"The
|
| 80 |
-
"
|
| 81 |
-
"looking exactly like thick orange powder, fine loose dust, or tiny accumulated pollen spores sitting entirely on top of the leaf surface. "
|
| 82 |
-
"The edges of these bright orange spots are soft, diffuse, and blurred, seamlessly blending into the surrounding green leaf tissue. "
|
| 83 |
-
"There are absolutely no sharp, well-defined dark borders. "
|
| 84 |
-
"The spots are irregular in shape and frequently merge together to form large, amorphous, powdery orange masses. "
|
| 85 |
-
"Crucially, the rust powder is never dark, never brown, and has absolutely no dark tones; it is exclusively bright yellow and vivid orange. "
|
| 86 |
-
"The leaf must NOT have any large circular dark-brown necrotic spots. "
|
| 87 |
-
"It completely lacks distinct dark brown concentric rings or 'bullseye' shapes, "
|
| 88 |
-
"and is clearly characterized by its vibrant, bright, powdery, and dusty orange texture without any dark dead tissue."
|
| 89 |
),
|
| 90 |
"Bicho Mineiro do Café": (
|
| 91 |
-
"A
|
| 92 |
-
"The
|
| 93 |
-
"
|
| 94 |
-
"Crucially, these large dead patches are frequently surrounded by a very prominent and wide bright yellow or pale-green halo. "
|
| 95 |
-
"The surface of the dead tissue looks wrinkled, completely dry, and papery, sometimes with peeling translucent skin. "
|
| 96 |
-
"It completely lacks any perfectly circular 'bullseye' spots with a central dot. "
|
| 97 |
-
"It completely lacks any pitch-black scorch marks on the extreme leaf edges. "
|
| 98 |
-
"It completely lacks any raised, powdery orange dust or granular texture."
|
| 99 |
),
|
| 100 |
"Mancha de Phoma": (
|
| 101 |
-
"A
|
| 102 |
-
"The
|
| 103 |
-
"
|
| 104 |
-
"It forms a solid, compact block of thick, dead rotting tissue, never a network of irregular serpentine galleries. "
|
| 105 |
-
"It often causes the leaf edge to curl and tear. "
|
| 106 |
-
"It frequently has tiny black dots (fungal fruiting bodies) inside the solid dark mass. "
|
| 107 |
-
"It is never a translucent, flat, hollow papery blister or a network of dry serpentine galleries in the middle of the leaf. "
|
| 108 |
-
"It completely lacks any perfectly circular geometries with a bright white central 'bullseye' dot. "
|
| 109 |
-
"It completely lacks any raised, bright, granular powdery orange dust."
|
| 110 |
)
|
| 111 |
}
|
| 112 |
|
|
@@ -140,7 +120,7 @@ def process_leaf_image(image_path, model_roboflow, long_model, long_preprocess,
|
|
| 140 |
|
| 141 |
# 1. DETECÇÃO (ROBOFLOW)
|
| 142 |
image = Image.open(image_path)
|
| 143 |
-
predictions = model_roboflow.infer(image, confidence=0.
|
| 144 |
detections = sv.Detections.from_inference(predictions)
|
| 145 |
|
| 146 |
img_width, img_height = image.size
|
|
@@ -230,6 +210,19 @@ def predict():
|
|
| 230 |
except Exception as e:
|
| 231 |
return jsonify({'error': str(e)}), 500
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
@app.route('/predict_batch', methods=['POST'])
|
| 234 |
def predict_batch():
|
| 235 |
if 'files' not in request.files:
|
|
@@ -247,6 +240,8 @@ def predict_batch():
|
|
| 247 |
text_features, class_names = get_text_features(long_model, text_descriptions_longclip, device)
|
| 248 |
|
| 249 |
batch_results = []
|
|
|
|
|
|
|
| 250 |
|
| 251 |
for idx, file in enumerate(files):
|
| 252 |
image_path = os.path.join(app.config['UPLOAD_FOLDER'], f"temp_leaf_batch_{idx}.jpg")
|
|
@@ -257,10 +252,22 @@ def predict_batch():
|
|
| 257 |
text_features, class_names, device
|
| 258 |
)
|
| 259 |
|
|
|
|
| 260 |
batch_results.append({
|
| 261 |
"filename": file.filename,
|
| 262 |
-
"mais_frequente":
|
| 263 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
# Consolidar a contagem da doença principal de cada folha do lote
|
| 266 |
doencas_principais = [res["mais_frequente"] for res in batch_results if res["mais_frequente"] != "Nenhuma detecção encontrada"]
|
|
@@ -277,15 +284,84 @@ def predict_batch():
|
|
| 277 |
"porcentagem": round(pct, 1)
|
| 278 |
}
|
| 279 |
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
"estatisticas": estatisticas,
|
| 282 |
"detalhes": batch_results,
|
| 283 |
"total_folhas": len(files),
|
| 284 |
-
"folhas_com_deteccao": total_validas
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
except Exception as e:
|
| 288 |
return jsonify({'error': str(e)}), 500
|
| 289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
if __name__ == '__main__':
|
| 291 |
app.run(debug=True, use_reloader=False)
|
|
|
|
| 32 |
|
| 33 |
app = Flask(__name__)
|
| 34 |
|
| 35 |
+
# Variável global para armazenar as análises em lote (Artigo)
|
| 36 |
+
resultados_globais_artigo = []
|
| 37 |
+
|
| 38 |
# --- CONFIGURAÇÕES INICIAIS ---
|
| 39 |
# A chave da API do Roboflow agora é carregada automaticamente do arquivo .env
|
| 40 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 68 |
# --- DICIONÁRIO DE DESCRIÇÕES OTIMIZADO PARA LONGCLIP ---
|
| 69 |
text_descriptions_longclip = {
|
| 70 |
"Mancha de Olho Pardo (Cercospora)": (
|
| 71 |
+
"A highly magnified view showing a distinct circular 'bullseye' or eye geometry. "
|
| 72 |
+
"The absolute center must present a lighter, silvery, pale, or white core. "
|
| 73 |
+
"This central pale area is obligatorily surrounded by prominent, dark concentric rings. "
|
| 74 |
+
"Outside these dark rings lies a diffuse yellow halo."
|
|
|
|
|
|
|
|
|
|
| 75 |
),
|
|
|
|
| 76 |
"Ferrugem do Cafeeiro": (
|
| 77 |
+
"A highly magnified view of bright, vivid cadmium-orange textures. "
|
| 78 |
+
"The surface is densely covered in thick powdery granular dust or accumulated pollen-like spores. "
|
| 79 |
+
"The bright orange fuzzy material forms soft, blurry, and diffuse shapes."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
),
|
| 81 |
"Bicho Mineiro do Café": (
|
| 82 |
+
"A highly magnified view of parched, light-tan or beige blisters. "
|
| 83 |
+
"The texture consists of flat, withered material with a highly wrinkled, translucent, and papery appearance. "
|
| 84 |
+
"It looks exactly like dry, flaky skin or torn parched parchment."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
),
|
| 86 |
"Mancha de Phoma": (
|
| 87 |
+
"A highly magnified view of a massive, solid, dark-brown or pitch-black necrotic mass. "
|
| 88 |
+
"The affliction appears as a severe, thick dark rot or burn. "
|
| 89 |
+
"It forms a continuous, opaque block of dark dead tissue, often causing the affected margins to become torn."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
)
|
| 91 |
}
|
| 92 |
|
|
|
|
| 120 |
|
| 121 |
# 1. DETECÇÃO (ROBOFLOW)
|
| 122 |
image = Image.open(image_path)
|
| 123 |
+
predictions = model_roboflow.infer(image, confidence=0.6)[0]
|
| 124 |
detections = sv.Detections.from_inference(predictions)
|
| 125 |
|
| 126 |
img_width, img_height = image.size
|
|
|
|
| 210 |
except Exception as e:
|
| 211 |
return jsonify({'error': str(e)}), 500
|
| 212 |
|
| 213 |
+
def get_true_class_from_filename(filename):
|
| 214 |
+
name_lower = filename.lower()
|
| 215 |
+
if 'ferrugem' in name_lower:
|
| 216 |
+
return "Ferrugem do Cafeeiro"
|
| 217 |
+
elif 'cercospora' in name_lower or 'olho pardo' in name_lower:
|
| 218 |
+
return "Mancha de Olho Pardo (Cercospora)"
|
| 219 |
+
elif 'mineiro' in name_lower or 'bicho' in name_lower:
|
| 220 |
+
return "Bicho Mineiro do Café"
|
| 221 |
+
elif 'phoma' in name_lower:
|
| 222 |
+
return "Mancha de Phoma"
|
| 223 |
+
else:
|
| 224 |
+
return None
|
| 225 |
+
|
| 226 |
@app.route('/predict_batch', methods=['POST'])
|
| 227 |
def predict_batch():
|
| 228 |
if 'files' not in request.files:
|
|
|
|
| 240 |
text_features, class_names = get_text_features(long_model, text_descriptions_longclip, device)
|
| 241 |
|
| 242 |
batch_results = []
|
| 243 |
+
y_true = []
|
| 244 |
+
y_pred = []
|
| 245 |
|
| 246 |
for idx, file in enumerate(files):
|
| 247 |
image_path = os.path.join(app.config['UPLOAD_FOLDER'], f"temp_leaf_batch_{idx}.jpg")
|
|
|
|
| 252 |
text_features, class_names, device
|
| 253 |
)
|
| 254 |
|
| 255 |
+
predicted_class = result["mais_frequente"]
|
| 256 |
batch_results.append({
|
| 257 |
"filename": file.filename,
|
| 258 |
+
"mais_frequente": predicted_class
|
| 259 |
})
|
| 260 |
+
|
| 261 |
+
# Extrair classe real: prioriza a seleção manual se existir, senão usa o nome do arquivo
|
| 262 |
+
manual_true_class = request.form.get('true_class')
|
| 263 |
+
if manual_true_class:
|
| 264 |
+
true_class = manual_true_class
|
| 265 |
+
else:
|
| 266 |
+
true_class = get_true_class_from_filename(file.filename)
|
| 267 |
+
|
| 268 |
+
if true_class and predicted_class != "Nenhuma detecção encontrada":
|
| 269 |
+
y_true.append(true_class)
|
| 270 |
+
y_pred.append(predicted_class)
|
| 271 |
|
| 272 |
# Consolidar a contagem da doença principal de cada folha do lote
|
| 273 |
doencas_principais = [res["mais_frequente"] for res in batch_results if res["mais_frequente"] != "Nenhuma detecção encontrada"]
|
|
|
|
| 284 |
"porcentagem": round(pct, 1)
|
| 285 |
}
|
| 286 |
|
| 287 |
+
# Calcular métricas de avaliação
|
| 288 |
+
metricas_avaliacao = {}
|
| 289 |
+
if len(y_true) > 0:
|
| 290 |
+
acertos = sum(1 for yt, yp in zip(y_true, y_pred) if yt == yp)
|
| 291 |
+
acuracia_geral = (acertos / len(y_true)) * 100
|
| 292 |
+
|
| 293 |
+
metricas_por_classe = {}
|
| 294 |
+
for cls in class_names:
|
| 295 |
+
tp = sum(1 for yt, yp in zip(y_true, y_pred) if yt == cls and yp == cls)
|
| 296 |
+
fp = sum(1 for yt, yp in zip(y_true, y_pred) if yt != cls and yp == cls)
|
| 297 |
+
fn = sum(1 for yt, yp in zip(y_true, y_pred) if yt == cls and yp != cls)
|
| 298 |
+
|
| 299 |
+
precision = (tp / (tp + fp)) * 100 if (tp + fp) > 0 else 0
|
| 300 |
+
recall = (tp / (tp + fn)) * 100 if (tp + fn) > 0 else 0
|
| 301 |
+
f1_score = (2 * precision * recall) / (precision + recall) if (precision + recall) > 0 else 0
|
| 302 |
+
|
| 303 |
+
metricas_por_classe[cls] = {
|
| 304 |
+
"precision": round(precision, 2),
|
| 305 |
+
"recall": round(recall, 2),
|
| 306 |
+
"f1_score": round(f1_score, 2),
|
| 307 |
+
"suporte": sum(1 for yt in y_true if yt == cls)
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
matriz_confusao = {}
|
| 311 |
+
for cls_real in class_names:
|
| 312 |
+
matriz_confusao[cls_real] = {}
|
| 313 |
+
for cls_pred in class_names:
|
| 314 |
+
matriz_confusao[cls_real][cls_pred] = sum(1 for yt, yp in zip(y_true, y_pred) if yt == cls_real and yp == cls_pred)
|
| 315 |
+
|
| 316 |
+
metricas_avaliacao = {
|
| 317 |
+
"acuracia_geral": round(acuracia_geral, 2),
|
| 318 |
+
"por_classe": metricas_por_classe,
|
| 319 |
+
"matriz_confusao": matriz_confusao,
|
| 320 |
+
"total_avaliado": len(y_true),
|
| 321 |
+
"dados_brutos": {
|
| 322 |
+
"y_true": y_true,
|
| 323 |
+
"y_pred": y_pred
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
resultado_final = {
|
| 328 |
"estatisticas": estatisticas,
|
| 329 |
"detalhes": batch_results,
|
| 330 |
"total_folhas": len(files),
|
| 331 |
+
"folhas_com_deteccao": total_validas,
|
| 332 |
+
"metricas_avaliacao": metricas_avaliacao
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
import datetime
|
| 336 |
+
timestamp_str = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
| 337 |
+
|
| 338 |
+
doencas_no_lote = list(set(y_true)) if len(y_true) > 0 else ["Desconhecida"]
|
| 339 |
+
|
| 340 |
+
for doenca in doencas_no_lote:
|
| 341 |
+
erros_confusao = {}
|
| 342 |
+
suporte = len(files)
|
| 343 |
+
if doenca != "Desconhecida" and "matriz_confusao" in metricas_avaliacao:
|
| 344 |
+
erros_confusao = metricas_avaliacao["matriz_confusao"].get(doenca, {})
|
| 345 |
+
suporte = metricas_avaliacao.get("por_classe", {}).get(doenca, {}).get("suporte", len(files))
|
| 346 |
+
|
| 347 |
+
resultados_globais_artigo.append({
|
| 348 |
+
"timestamp": timestamp_str,
|
| 349 |
+
"doenca_alvo": doenca,
|
| 350 |
+
"total_folhas": suporte,
|
| 351 |
+
"estatisticas": estatisticas,
|
| 352 |
+
"acuracia_geral": metricas_avaliacao.get("acuracia_geral", 0),
|
| 353 |
+
"metricas_classe": metricas_avaliacao.get("por_classe", {}).get(doenca, {}) if doenca != "Desconhecida" else {},
|
| 354 |
+
"erros_confusao": erros_confusao
|
| 355 |
+
})
|
| 356 |
+
|
| 357 |
+
return jsonify(resultado_final)
|
| 358 |
|
| 359 |
except Exception as e:
|
| 360 |
return jsonify({'error': str(e)}), 500
|
| 361 |
|
| 362 |
+
@app.route('/resultados_artigo')
|
| 363 |
+
def resultados_artigo():
|
| 364 |
+
return render_template('resultados_artigo.html', dados=resultados_globais_artigo)
|
| 365 |
+
|
| 366 |
if __name__ == '__main__':
|
| 367 |
app.run(debug=True, use_reloader=False)
|
templates/index.html
CHANGED
|
@@ -124,6 +124,19 @@
|
|
| 124 |
<p><strong>Lote:</strong> Selecione múltiplas folhas. O resultado será um resumo geral de todas as imagens processadas.</p>
|
| 125 |
</div>
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
<button id="batch-analyze-btn" class="primary-btn" disabled>
|
| 128 |
<span class="btn-text" id="batch-btn-text"><i class="ph-bold ph-scan"></i> Analisar Lote</span>
|
| 129 |
<span class="loader hidden" id="batch-loader"></span>
|
|
@@ -165,6 +178,29 @@
|
|
| 165 |
<p id="save-result-msg-batch" style="font-size: 0.85rem; color: var(--text-secondary); margin-top: 8px; display: none;"></p>
|
| 166 |
</div>
|
| 167 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
</div>
|
| 169 |
</section>
|
| 170 |
</div>
|
|
|
|
| 124 |
<p><strong>Lote:</strong> Selecione múltiplas folhas. O resultado será um resumo geral de todas as imagens processadas.</p>
|
| 125 |
</div>
|
| 126 |
|
| 127 |
+
<a href="/resultados_artigo" target="_blank" style="display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; margin-bottom: 15px; margin-top: 10px; background-color: #34495e; color: white; border-radius: 8px; text-decoration: none; font-weight: 600; transition: background-color 0.2s;" onmouseover="this.style.backgroundColor='#2c3e50'" onmouseout="this.style.backgroundColor='#34495e'"><i class="ph-bold ph-table"></i> Ver Tabela Consolidada (Artigo)</a>
|
| 128 |
+
|
| 129 |
+
<div class="batch-ground-truth-selector" style="margin: 15px 0; display: flex; flex-direction: column; gap: 8px;">
|
| 130 |
+
<label for="batch-true-class" style="font-size: 0.9rem; font-weight: 600; color: var(--text-secondary);"><i class="ph-bold ph-tag"></i> Classe Real (Opcional - Para Métricas)</label>
|
| 131 |
+
<select id="batch-true-class" style="padding: 12px; border-radius: 8px; border: 1px solid #e2e8f0; font-family: inherit; font-size: 0.95rem; background-color: white; color: var(--text-primary); cursor: pointer;">
|
| 132 |
+
<option value="auto">Detectar pelo nome do arquivo</option>
|
| 133 |
+
<option value="Ferrugem do Cafeeiro">Ferrugem do Cafeeiro</option>
|
| 134 |
+
<option value="Mancha de Olho Pardo (Cercospora)">Mancha de Olho Pardo (Cercospora)</option>
|
| 135 |
+
<option value="Bicho Mineiro do Café">Bicho Mineiro do Café</option>
|
| 136 |
+
<option value="Mancha de Phoma">Mancha de Phoma</option>
|
| 137 |
+
</select>
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
<button id="batch-analyze-btn" class="primary-btn" disabled>
|
| 141 |
<span class="btn-text" id="batch-btn-text"><i class="ph-bold ph-scan"></i> Analisar Lote</span>
|
| 142 |
<span class="loader hidden" id="batch-loader"></span>
|
|
|
|
| 178 |
<p id="save-result-msg-batch" style="font-size: 0.85rem; color: var(--text-secondary); margin-top: 8px; display: none;"></p>
|
| 179 |
</div>
|
| 180 |
</div>
|
| 181 |
+
|
| 182 |
+
<!-- Métricas de Avaliação -->
|
| 183 |
+
<div id="batch-metrics-container" class="hidden" style="background-color: white; border: 1px solid #e2e8f0; border-radius: 12px; padding: 25px; margin-bottom: 25px;">
|
| 184 |
+
<h3 style="color: var(--text-secondary); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 15px; text-align: center;"><i class="ph-bold ph-chart-line-up"></i> Métricas de Avaliação</h3>
|
| 185 |
+
<p style="text-align: center; font-size: 0.9rem; color: #718096; margin-bottom: 15px;">Acurácia Geral: <strong id="metric-accuracy" style="color: var(--accent-primary); font-size: 1.1rem;">-</strong> <span id="metric-total-evaluated" style="font-size: 0.8rem;"></span></p>
|
| 186 |
+
|
| 187 |
+
<div style="overflow-x: auto;">
|
| 188 |
+
<table style="width: 100%; border-collapse: collapse; text-align: left; font-size: 0.9rem;">
|
| 189 |
+
<thead>
|
| 190 |
+
<tr style="border-bottom: 2px solid #e2e8f0;">
|
| 191 |
+
<th style="padding: 10px; color: var(--text-secondary);">Classe</th>
|
| 192 |
+
<th style="padding: 10px; color: var(--text-secondary);">Precisão</th>
|
| 193 |
+
<th style="padding: 10px; color: var(--text-secondary);">Recall</th>
|
| 194 |
+
<th style="padding: 10px; color: var(--text-secondary);">F1-Score</th>
|
| 195 |
+
<th style="padding: 10px; color: var(--text-secondary);">Suporte</th>
|
| 196 |
+
</tr>
|
| 197 |
+
</thead>
|
| 198 |
+
<tbody id="metrics-table-body">
|
| 199 |
+
<!-- Injetado via JS -->
|
| 200 |
+
</tbody>
|
| 201 |
+
</table>
|
| 202 |
+
</div>
|
| 203 |
+
</div>
|
| 204 |
</div>
|
| 205 |
</section>
|
| 206 |
</div>
|
templates/resultados_artigo.html
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="pt-br">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Resultados das Análises para o Artigo</title>
|
| 7 |
+
<style>
|
| 8 |
+
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f7f6; margin: 0; padding: 20px; color: #333; }
|
| 9 |
+
h1 { text-align: center; color: #2c3e50; }
|
| 10 |
+
.table-container { width: 95%; margin: 20px auto; overflow-x: auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
|
| 11 |
+
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
|
| 12 |
+
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; }
|
| 13 |
+
th { background-color: #34495e; color: #fff; font-weight: 600; text-transform: uppercase; font-size: 0.9em; }
|
| 14 |
+
tr:hover { background-color: #f1f1f1; }
|
| 15 |
+
.no-data { text-align: center; font-size: 1.2em; color: #7f8c8d; margin-top: 50px; }
|
| 16 |
+
.btn-voltar { display: inline-block; margin-bottom: 20px; padding: 10px 20px; background-color: #27ae60; color: white; text-decoration: none; border-radius: 5px; font-weight: bold; }
|
| 17 |
+
.btn-voltar:hover { background-color: #2ecc71; }
|
| 18 |
+
ul { margin: 0; padding-left: 15px; font-size: 0.9em; color: #e74c3c; }
|
| 19 |
+
</style>
|
| 20 |
+
</head>
|
| 21 |
+
<body>
|
| 22 |
+
|
| 23 |
+
<div class="table-container">
|
| 24 |
+
<a href="/" class="btn-voltar">← Voltar ao Início</a>
|
| 25 |
+
<h1>Tabela de Resultados Consolidada</h1>
|
| 26 |
+
<p style="text-align: center; color: #666;">A cada nova análise em lote (ex: 50 imagens de uma doença), os dados são acumulados nesta tabela como uma nova linha.</p>
|
| 27 |
+
|
| 28 |
+
{% if dados %}
|
| 29 |
+
<table>
|
| 30 |
+
<thead>
|
| 31 |
+
<tr>
|
| 32 |
+
<th>Data/Hora</th>
|
| 33 |
+
<th>Doença Alvo (Lote)</th>
|
| 34 |
+
<th>Total de Folhas</th>
|
| 35 |
+
<th>Acurácia Geral</th>
|
| 36 |
+
<th>Precisão</th>
|
| 37 |
+
<th>Recall</th>
|
| 38 |
+
<th>F1-Score</th>
|
| 39 |
+
<th>Erros de Classificação (Confusão)</th>
|
| 40 |
+
</tr>
|
| 41 |
+
</thead>
|
| 42 |
+
<tbody>
|
| 43 |
+
{% for item in dados %}
|
| 44 |
+
<tr>
|
| 45 |
+
<td>{{ item.timestamp }}</td>
|
| 46 |
+
<td><strong>{{ item.doenca_alvo }}</strong></td>
|
| 47 |
+
<td>{{ item.total_folhas }}</td>
|
| 48 |
+
<td>{{ item.acuracia_geral }}%</td>
|
| 49 |
+
<td>{{ item.metricas_classe.get('precision', '-') }}%</td>
|
| 50 |
+
<td>{{ item.metricas_classe.get('recall', '-') }}%</td>
|
| 51 |
+
<td>{{ item.metricas_classe.get('f1_score', '-') }}%</td>
|
| 52 |
+
<td>
|
| 53 |
+
<ul>
|
| 54 |
+
{% if item.erros_confusao %}
|
| 55 |
+
{% for classe_predita, quantidade in item.erros_confusao.items() %}
|
| 56 |
+
{% if classe_predita != item.doenca_alvo and quantidade > 0 %}
|
| 57 |
+
<li>{{ classe_predita }}: {{ quantidade }} imgs</li>
|
| 58 |
+
{% endif %}
|
| 59 |
+
{% endfor %}
|
| 60 |
+
{% else %}
|
| 61 |
+
{% for classe, est in item.estatisticas.items() %}
|
| 62 |
+
{% if classe != item.doenca_alvo and est.quantidade > 0 %}
|
| 63 |
+
<li>{{ classe }}: {{ est.quantidade }} imgs ({{ est.porcentagem }}%)</li>
|
| 64 |
+
{% endif %}
|
| 65 |
+
{% endfor %}
|
| 66 |
+
{% endif %}
|
| 67 |
+
</ul>
|
| 68 |
+
</td>
|
| 69 |
+
</tr>
|
| 70 |
+
{% endfor %}
|
| 71 |
+
</tbody>
|
| 72 |
+
</table>
|
| 73 |
+
{% else %}
|
| 74 |
+
<div class="no-data">Nenhuma análise em lote foi realizada ainda. Faça o upload das imagens para ver os resultados aqui!</div>
|
| 75 |
+
{% endif %}
|
| 76 |
+
</div>
|
| 77 |
+
|
| 78 |
+
</body>
|
| 79 |
+
</html>
|