leygit commited on
Commit
a74de4c
·
verified ·
1 Parent(s): 7d9d8d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -94,11 +94,25 @@ def evaluate_model_with_report(val_loader):
94
  # Performance metrics
95
  def generate_performance_metrics():
96
  model.eval() # Set model to evaluation mode
97
-
98
- y_pred = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  accuracy = accuracy_score(y_true, y_pred)
100
  report = classification_report(y_true, y_pred, output_dict=True)
101
-
102
  return {
103
  "accuracy": f"{accuracy:.2%}",
104
  "precision": f"{report['1']['precision']:.2%}",
@@ -106,7 +120,6 @@ def generate_performance_metrics():
106
  "f1_score": f"{report['1']['f1-score']:.2%}",
107
  }
108
 
109
-
110
  # Gradio Interface
111
 
112
  def create_interface():
 
94
  # Performance metrics
95
  def generate_performance_metrics():
96
  model.eval() # Set model to evaluation mode
97
+
98
+ y_true = [] # True labels
99
+ y_pred = [] # Predicted labels
100
+
101
+ with torch.no_grad():
102
+ for batch in val_loader:
103
+ inputs = {key: val.to(device) for key, val in batch.items()}
104
+ labels = inputs.pop("labels").to(device)
105
+
106
+ outputs = model(**inputs)
107
+ prediction = torch.argmax(outputs.logits, dim=1).item()
108
+
109
+ y_true.append(label)
110
+ y_pred.append(prediction)
111
+
112
+ # Compute accuracy and classification report
113
  accuracy = accuracy_score(y_true, y_pred)
114
  report = classification_report(y_true, y_pred, output_dict=True)
115
+
116
  return {
117
  "accuracy": f"{accuracy:.2%}",
118
  "precision": f"{report['1']['precision']:.2%}",
 
120
  "f1_score": f"{report['1']['f1-score']:.2%}",
121
  }
122
 
 
123
  # Gradio Interface
124
 
125
  def create_interface():