Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
import xgboost as xgb
|
5 |
+
import pickle
|
6 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
7 |
+
|
8 |
+
|
9 |
+
os.environ["WANDB_DISABLED"] = "true"
|
10 |
+
|
11 |
+
label2id = {
|
12 |
+
0: "negative",
|
13 |
+
1: "neutral",
|
14 |
+
2: "positive"
|
15 |
+
}
|
16 |
+
# names of the files saved in step 2: Training
|
17 |
+
|
18 |
+
model_file_name = "model.pkl"
|
19 |
+
vectorizer_file_name = 'vectorizer.pk'
|
20 |
+
|
21 |
+
|
22 |
+
# load
|
23 |
+
xgb_model_loaded = pickle.load(open(model_file_name, "rb"))
|
24 |
+
vectorizer_loaded = pickle.load(open(vectorizer_file_name, "rb"))
|
25 |
+
|
26 |
+
|
27 |
+
def predict_sentiment(predict_texts):
|
28 |
+
predictions_loaded = xgb_model_loaded.predict(vectorizer_loaded.transform([predict_texts]))
|
29 |
+
print(predictions_loaded)
|
30 |
+
return label2id[predictions_loaded[0]]
|
31 |
+
|
32 |
+
|
33 |
+
interface = gr.Interface(
|
34 |
+
fn=predict_sentiment,
|
35 |
+
inputs='text',
|
36 |
+
outputs=['text'],
|
37 |
+
title='Croatian Book reviews Sentiment Analysis',
|
38 |
+
examples= ["Volim kavu","Ne volim kavu"],
|
39 |
+
description='Get the positive/neutral/negative sentiment for the given input.'
|
40 |
+
)
|
41 |
+
|
42 |
+
interface.launch(inline = False)
|