Spaces:
Sleeping
Sleeping
evaluate update
Browse files- qwen_classifier/evaluate.py +19 -2
qwen_classifier/evaluate.py
CHANGED
@@ -7,8 +7,8 @@ import pandas as pd
|
|
7 |
import torch
|
8 |
from datasets import Dataset
|
9 |
from torch.utils.data import DataLoader
|
10 |
-
|
11 |
-
from .
|
12 |
|
13 |
def load_data(test_data_path):
|
14 |
# zip file handler
|
@@ -119,3 +119,20 @@ def _evaluate_local(test_data_path, hf_repo):
|
|
119 |
report = classification_report(all_labels, all_preds, target_names=TAG_NAMES, zero_division=0)
|
120 |
|
121 |
return metrics, report
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import torch
|
8 |
from datasets import Dataset
|
9 |
from torch.utils.data import DataLoader
|
10 |
+
import requests
|
11 |
+
from .config import TAG_NAMES, DEVICE, SPACE_URL
|
12 |
|
13 |
def load_data(test_data_path):
|
14 |
# zip file handler
|
|
|
119 |
report = classification_report(all_labels, all_preds, target_names=TAG_NAMES, zero_division=0)
|
120 |
|
121 |
return metrics, report
|
122 |
+
|
123 |
+
|
124 |
+
def _evaluate_hf_api(text, hf_token=None):
|
125 |
+
try:
|
126 |
+
response = requests.post(
|
127 |
+
f"{SPACE_URL}/evaluate",
|
128 |
+
json={"text": text}, # This matches the Pydantic model
|
129 |
+
headers={
|
130 |
+
"Authorization": f"Bearer {hf_token}",
|
131 |
+
"Content-Type": "application/json"
|
132 |
+
} if hf_token else {"Content-Type": "application/json"},
|
133 |
+
timeout=10
|
134 |
+
)
|
135 |
+
response.raise_for_status() # Raise HTTP errors
|
136 |
+
return response.json()
|
137 |
+
except requests.exceptions.RequestException as e:
|
138 |
+
raise ValueError(f"API Error: {str(e)}\nResponse: {e.response.text if hasattr(e, 'response') else ''}")
|