Spaces:
Runtime error
Runtime error
Commit
·
cd94a38
1
Parent(s):
168eed2
ready
Browse files- app.py +5 -0
- tasks/text.py +7 -24
app.py
CHANGED
@@ -2,6 +2,11 @@ from fastapi import FastAPI
|
|
2 |
from dotenv import load_dotenv
|
3 |
from tasks import text, image, audio
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
# Load environment variables
|
6 |
load_dotenv()
|
7 |
|
|
|
2 |
from dotenv import load_dotenv
|
3 |
from tasks import text, image, audio
|
4 |
|
5 |
+
from skops.hub_utils import download
|
6 |
+
|
7 |
+
#download model for text task
|
8 |
+
download(repo_id = "kantundpeterpan/frugal-ai-toy", dst = "text/model")
|
9 |
+
|
10 |
# Load environment variables
|
11 |
load_dotenv()
|
12 |
|
tasks/text.py
CHANGED
@@ -15,25 +15,10 @@ import joblib
|
|
15 |
REPO_ID = "kantundpeterpan/frugal-ai-toy"
|
16 |
FILENAME = "tfidf_rf.skops"
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
# import string
|
23 |
-
# nltk.download('stopwords')
|
24 |
-
|
25 |
-
# stop = set(stopwords.words('english') + list(string.punctuation))
|
26 |
-
|
27 |
-
# def tokenize_quote(r):
|
28 |
-
# tokens = nltk.word_tokenize(r.lower())
|
29 |
-
# cleaned = [word for word in tokens if word not in stop]
|
30 |
-
# return cleaned
|
31 |
-
|
32 |
-
# def lemmatize_tokens(tokens: list):
|
33 |
-
# return [lemmatizer.lemmatize(t) for t in tokens]
|
34 |
-
|
35 |
-
# def lemmatize_X(X):
|
36 |
-
# return X.quote.apply(tokenize_quote).apply(lemmatize_tokens).apply(lambda x: " ".join(x))
|
37 |
|
38 |
import random
|
39 |
|
@@ -80,6 +65,7 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
80 |
train_test = dataset["train"].train_test_split(test_size=request.test_size, seed=request.test_seed)
|
81 |
test_dataset = train_test["test"]
|
82 |
test_df = pd.DataFrame(test_dataset)
|
|
|
83 |
|
84 |
# Start tracking emissions
|
85 |
tracker.start()
|
@@ -90,14 +76,11 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
90 |
# 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.
|
91 |
#--------------------------------------------------------------------------------------------
|
92 |
|
93 |
-
|
94 |
-
#download model
|
95 |
-
download(repo_id = "kantundpeterpan/frugal-ai-toy", dst = "skops_test")
|
96 |
#get unknwown types
|
97 |
-
unknown = skops.io.get_untrusted_types(file = "
|
98 |
|
99 |
#load model
|
100 |
-
model = model = load("
|
101 |
|
102 |
# Make predictions
|
103 |
true_labels = test_dataset["label"]
|
|
|
15 |
REPO_ID = "kantundpeterpan/frugal-ai-toy"
|
16 |
FILENAME = "tfidf_rf.skops"
|
17 |
|
18 |
+
#add model directory to python path to be able to load tools.py
|
19 |
+
import sys
|
20 |
+
import os
|
21 |
+
sys.path.append(os.path.abspath('model'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
import random
|
24 |
|
|
|
65 |
train_test = dataset["train"].train_test_split(test_size=request.test_size, seed=request.test_seed)
|
66 |
test_dataset = train_test["test"]
|
67 |
test_df = pd.DataFrame(test_dataset)
|
68 |
+
print(test_df.head())
|
69 |
|
70 |
# Start tracking emissions
|
71 |
tracker.start()
|
|
|
76 |
# 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.
|
77 |
#--------------------------------------------------------------------------------------------
|
78 |
|
|
|
|
|
|
|
79 |
#get unknwown types
|
80 |
+
unknown = skops.io.get_untrusted_types(file = "model/tfidf_rf.skops")
|
81 |
|
82 |
#load model
|
83 |
+
model = model = load("model/tfidf_rf.skops", trusted = unknown)
|
84 |
|
85 |
# Make predictions
|
86 |
true_labels = test_dataset["label"]
|