File size: 1,044 Bytes
990dc13
 
 
e793ba7
043a02e
e793ba7
990dc13
043a02e
e793ba7
990dc13
043a02e
 
 
 
 
 
 
50ca09f
 
990dc13
043a02e
e793ba7
 
 
990dc13
043a02e
e793ba7
043a02e
 
 
990dc13
 
 
 
 
b1ce276
043a02e
18f2d2a
990dc13
 
 
043a02e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
import os
import gradio as gr
import xgboost as xgb
import pickle
from sklearn.feature_extraction.text import TfidfVectorizer


os.environ["WANDB_DISABLED"] = "true"

label2id =  {
    0: "negative",
    1: "neutral",
    2: "positive"
  }
# names of the files saved in step 2: Training

model_file_name = "xgb_reg_dg.pkl"
vectorizer_file_name = 'vectorizer_dg.pk'


# load
xgb_model_loaded = pickle.load(open(model_file_name, "rb"))
vectorizer_loaded = pickle.load(open(vectorizer_file_name, "rb"))


def predict_sentiment(predict_texts):
    predictions_loaded = xgb_model_loaded.predict(vectorizer_loaded.transform([predict_texts]))
    print(predictions_loaded)
    return label2id[predictions_loaded[0]]


interface = gr.Interface(
    fn=predict_sentiment,
    inputs='text',
    outputs=['text'],
    title='Croatian Book reviews Sentiment Analysis',
    examples= ["Volim kavu","Ne volim kavu"],
    description='Get the positive/neutral/negative sentiment for the given input.'
)

interface.launch(inline = False)