Update app.py
Browse files
app.py
CHANGED
|
@@ -143,14 +143,14 @@ def generate_performance_metrics():
|
|
| 143 |
|
| 144 |
with torch.no_grad():
|
| 145 |
for batch in val_loader:
|
| 146 |
-
inputs =
|
| 147 |
-
|
| 148 |
|
| 149 |
outputs = model(**inputs)
|
| 150 |
-
|
| 151 |
|
| 152 |
-
y_true.
|
| 153 |
-
y_pred.
|
| 154 |
|
| 155 |
# Compute accuracy and classification report
|
| 156 |
accuracy = accuracy_score(y_true, y_pred)
|
|
@@ -164,6 +164,7 @@ def generate_performance_metrics():
|
|
| 164 |
}
|
| 165 |
|
| 166 |
|
|
|
|
| 167 |
# Gradio Interface
|
| 168 |
|
| 169 |
def create_interface():
|
|
|
|
| 143 |
|
| 144 |
with torch.no_grad():
|
| 145 |
for batch in val_loader:
|
| 146 |
+
inputs = {key: val.to(device) for key, val in batch.items()}
|
| 147 |
+
labels = inputs.pop("labels").to(device) # Extract labels
|
| 148 |
|
| 149 |
outputs = model(**inputs)
|
| 150 |
+
predictions = torch.argmax(outputs.logits, dim=1)
|
| 151 |
|
| 152 |
+
y_true.extend(labels.cpu().numpy())
|
| 153 |
+
y_pred.extend(predictions.cpu().numpy())
|
| 154 |
|
| 155 |
# Compute accuracy and classification report
|
| 156 |
accuracy = accuracy_score(y_true, y_pred)
|
|
|
|
| 164 |
}
|
| 165 |
|
| 166 |
|
| 167 |
+
|
| 168 |
# Gradio Interface
|
| 169 |
|
| 170 |
def create_interface():
|