KarloB7 commited on
Commit
255d37f
1 Parent(s): 67364fd

Upload 4 files

Browse files
Files changed (4) hide show
  1. Komentari Anotirani.docx +0 -0
  2. app.py +42 -0
  3. model.pkl +3 -0
  4. vectorizer.pk +0 -0
Komentari Anotirani.docx ADDED
Binary file (78.1 kB). View file
 
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 = "xgb_reg_dg.pkl"
19
+ vectorizer_file_name = 'vectorizer_dg.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)
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9409399c00c3e769a42dec5f11f7860f50e5a2be87a9371687fca1bc9dc9af52
3
+ size 578394
vectorizer.pk ADDED
Binary file (203 kB). View file