kantundpeterpan commited on
Commit
712302e
·
verified ·
1 Parent(s): 9685f7b

Update tasks/text.py

Browse files
Files changed (1) hide show
  1. tasks/text.py +19 -3
tasks/text.py CHANGED
@@ -2,6 +2,20 @@ from fastapi import APIRouter
2
  from datetime import datetime
3
  from datasets import load_dataset
4
  from sklearn.metrics import accuracy_score
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import random
6
 
7
  from .utils.evaluation import TextEvaluationRequest
@@ -9,7 +23,7 @@ from .utils.emissions import tracker, clean_emissions_data, get_space_info
9
 
10
  router = APIRouter()
11
 
12
- DESCRIPTION = "Random Baseline"
13
  ROUTE = "/text"
14
 
15
  @router.post(ROUTE, tags=["Text Task"],
@@ -55,10 +69,12 @@ async def evaluate_text(request: TextEvaluationRequest):
55
  # YOUR MODEL INFERENCE CODE HERE
56
  # Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
57
  #--------------------------------------------------------------------------------------------
58
-
59
  # Make random predictions (placeholder for actual model inference)
60
  true_labels = test_dataset["label"]
61
- predictions = [random.randint(0, 7) for _ in range(len(true_labels))]
 
 
62
 
63
  #--------------------------------------------------------------------------------------------
64
  # YOUR MODEL INFERENCE STOPS HERE
 
2
  from datetime import datetime
3
  from datasets import load_dataset
4
  from sklearn.metrics import accuracy_score
5
+
6
+ from skops import hub_utils
7
+ from skops.io import load
8
+
9
+ from huggingface_hub import hf_hub_download
10
+ import joblib
11
+
12
+ REPO_ID = "kantundpeterpan/frugal-ai-toy"
13
+ FILENAME = "tfidf_rf.pkl"
14
+
15
+ model = joblib.load(
16
+ hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
17
+ )
18
+
19
  import random
20
 
21
  from .utils.evaluation import TextEvaluationRequest
 
23
 
24
  router = APIRouter()
25
 
26
+ DESCRIPTION = "tfidf-rf"
27
  ROUTE = "/text"
28
 
29
  @router.post(ROUTE, tags=["Text Task"],
 
69
  # YOUR MODEL INFERENCE CODE HERE
70
  # Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
71
  #--------------------------------------------------------------------------------------------
72
+
73
  # Make random predictions (placeholder for actual model inference)
74
  true_labels = test_dataset["label"]
75
+ predictions = [
76
+ LABEL_MAPPING[r] for r in model.predict(test_dataset)
77
+ ]
78
 
79
  #--------------------------------------------------------------------------------------------
80
  # YOUR MODEL INFERENCE STOPS HERE