Update app.py
Browse files
app.py
CHANGED
|
@@ -52,22 +52,18 @@ def predict(image: Image.Image) -> Dict[str, float]:
|
|
| 52 |
"""
|
| 53 |
try:
|
| 54 |
image = image.convert("RGB")
|
| 55 |
-
image_tensor = preprocess(image).unsqueeze(0)
|
| 56 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 57 |
-
image_tensor = image_tensor.to(device)
|
| 58 |
-
model.to(device)
|
| 59 |
|
| 60 |
with torch.no_grad():
|
| 61 |
output = model(image_tensor)
|
| 62 |
scores = torch.nn.functional.softmax(output[0], dim=0)
|
| 63 |
|
| 64 |
predictions = {label: float(score) for label, score in zip(labels, scores)}
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
return sorted_predictions
|
| 68 |
except Exception as e:
|
| 69 |
return {"error": str(e)}
|
| 70 |
|
|
|
|
| 71 |
title = "🔥 Skin-AI"
|
| 72 |
description = (
|
| 73 |
"🔬 **Skin-AI — AI-Powered Skin Disease Classification**\n\n"
|
|
|
|
| 52 |
"""
|
| 53 |
try:
|
| 54 |
image = image.convert("RGB")
|
| 55 |
+
image_tensor = preprocess(image).unsqueeze(0).to(model.device) # Используем device модели
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
with torch.no_grad():
|
| 58 |
output = model(image_tensor)
|
| 59 |
scores = torch.nn.functional.softmax(output[0], dim=0)
|
| 60 |
|
| 61 |
predictions = {label: float(score) for label, score in zip(labels, scores)}
|
| 62 |
+
return dict(sorted(predictions.items(), key=lambda item: item[1], reverse=True))
|
|
|
|
|
|
|
| 63 |
except Exception as e:
|
| 64 |
return {"error": str(e)}
|
| 65 |
|
| 66 |
+
|
| 67 |
title = "🔥 Skin-AI"
|
| 68 |
description = (
|
| 69 |
"🔬 **Skin-AI — AI-Powered Skin Disease Classification**\n\n"
|