Spaces:
Sleeping
Sleeping
SuperViktor2
commited on
Commit
•
07d5446
1
Parent(s):
a67ee09
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,24 @@
|
|
1 |
import numpy as np
|
2 |
import os
|
3 |
import gradio as gr
|
|
|
|
|
4 |
|
5 |
os.environ["WANDB_DISABLED"] = "true"
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
AutoConfig,
|
10 |
-
# AutoModelForSequenceClassification,
|
11 |
-
AutoTokenizer,
|
12 |
-
TrainingArguments,
|
13 |
-
logging,
|
14 |
-
pipeline
|
15 |
-
)
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# model_name =
|
21 |
-
|
22 |
-
|
23 |
-
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
24 |
-
|
25 |
-
# config = AutoConfig.from_pretrained(model_name)
|
26 |
-
|
27 |
-
# pipe = pipeline("text-classification")
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
label2id = {
|
35 |
-
"LABEL_0": "negative",
|
36 |
-
"LABEL_1": "neutral",
|
37 |
-
"LABEL_2": "positive"
|
38 |
-
}
|
39 |
-
|
40 |
-
analyzer = pipeline(
|
41 |
-
|
42 |
-
"sentiment-analysis", model="thak123/Cro-Frida", tokenizer="EMBEDDIA/crosloengual-bert"
|
43 |
-
|
44 |
-
)
|
45 |
-
def predict_sentiment(x):
|
46 |
-
return label2id[analyzer(x)[0]["label"]]
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
interface = gr.Interface(
|
50 |
fn=predict_sentiment,
|
|
|
1 |
import numpy as np
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
+
import xgboost as xgb
|
5 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
6 |
|
7 |
os.environ["WANDB_DISABLED"] = "true"
|
8 |
|
9 |
+
model_file_name = "xgb_reg.pkl"
|
10 |
+
vectorizer_file_name = 'vectorizer.pk'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
#load
|
13 |
+
xgb_model_loaded = pickle.load(open(model_file_name, "rb"))
|
14 |
+
vectorizer_loaded = pickle.load(open(vectorizer_file_name, "rb"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# predict
|
17 |
+
def predict_sentiment(predict_texts):
|
18 |
+
predictions_loaded = xgb_model_loaded.predict(
|
19 |
+
vectorizer_loaded.transform(predict_texts))
|
20 |
+
return vectorizer_loaded
|
21 |
+
#le.inverse_transform(predictions_loaded)
|
22 |
|
23 |
interface = gr.Interface(
|
24 |
fn=predict_sentiment,
|