Spaces:
Sleeping
Sleeping
hf space name
Browse files- qwen_classifier/evaluate.py +41 -0
- qwen_classifier/predict.py +1 -1
- setup.py +2 -1
qwen_classifier/evaluate.py
CHANGED
@@ -1,5 +1,46 @@
|
|
1 |
import numpy as np
|
2 |
from sklearn.metrics import classification_report
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def evaluate_model(test_data_path):
|
5 |
# Load your test data
|
|
|
1 |
import numpy as np
|
2 |
from sklearn.metrics import classification_report
|
3 |
+
import zipfile
|
4 |
+
import json
|
5 |
+
import pandas as pd
|
6 |
+
from .config import TAG_NAMES
|
7 |
+
|
8 |
+
def load_data(test_data_path):
|
9 |
+
# zip file handler
|
10 |
+
zip_file = zipfile.ZipFile('code_classification_dataset.zip')
|
11 |
+
|
12 |
+
# list available files in the container
|
13 |
+
names = zip_file.namelist()
|
14 |
+
data = []
|
15 |
+
features = ["prob_desc_description","prob_desc_input_spec","prob_desc_output_spec"]
|
16 |
+
cols = features + ["tags"]
|
17 |
+
# extract a specific file from the zip container
|
18 |
+
for name in names[1:]:
|
19 |
+
f = zip_file.open(name)
|
20 |
+
|
21 |
+
# save the extraced file
|
22 |
+
content = f.read()
|
23 |
+
d = json.loads(content)
|
24 |
+
# json_fmt = json.dumps(d, indent=2)
|
25 |
+
# print(json_fmt)
|
26 |
+
row = []
|
27 |
+
for c in cols:
|
28 |
+
row.append(d[c])
|
29 |
+
data.append(row)
|
30 |
+
df = pd.DataFrame(data, columns=cols)
|
31 |
+
return df
|
32 |
+
|
33 |
+
def preprocessing(df):
|
34 |
+
# Example dataset
|
35 |
+
texts = df["prob_desc_description"].values.tolist()
|
36 |
+
labels = df[TAG_NAMES].values.tolist()
|
37 |
+
|
38 |
+
# data:
|
39 |
+
# texts = ["text1", "text2", ...] # list of texts
|
40 |
+
# labels = [[0,1,0,0,1,0,1,1,0], [0,1,1,0,0,0,0,0,0],, ...] # list of labels
|
41 |
+
|
42 |
+
df = pd.DataFrame({'text':texts, 'labels': labels})
|
43 |
+
|
44 |
|
45 |
def evaluate_model(test_data_path):
|
46 |
# Load your test data
|
qwen_classifier/predict.py
CHANGED
@@ -32,7 +32,7 @@ def _predict_local(text, hf_repo):
|
|
32 |
|
33 |
def _predict_hf_api(text, hf_token=None):
|
34 |
# Use your Space endpoint instead of direct model API
|
35 |
-
SPACE_URL = "https://
|
36 |
|
37 |
try:
|
38 |
response = requests.post(
|
|
|
32 |
|
33 |
def _predict_hf_api(text, hf_token=None):
|
34 |
# Use your Space endpoint instead of direct model API
|
35 |
+
SPACE_URL = "https://keivanr-qwen-classifier-demo.hf.space"
|
36 |
|
37 |
try:
|
38 |
response = requests.post(
|
setup.py
CHANGED
@@ -10,7 +10,8 @@ setup(
|
|
10 |
'click',
|
11 |
'scikit-learn',
|
12 |
'huggingface_hub',
|
13 |
-
'requests'
|
|
|
14 |
],
|
15 |
entry_points={
|
16 |
'console_scripts': [
|
|
|
10 |
'click',
|
11 |
'scikit-learn',
|
12 |
'huggingface_hub',
|
13 |
+
'requests',
|
14 |
+
'pandas'
|
15 |
],
|
16 |
entry_points={
|
17 |
'console_scripts': [
|