thak123 commited on
Commit
043a02e
·
verified ·
1 Parent(s): 4a09be7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,34 +1,42 @@
1
  import numpy as np
2
  import os
3
  import gradio as gr
4
- import pickle
5
-
6
  import xgboost as xgb
 
7
  from sklearn.feature_extraction.text import TfidfVectorizer
8
 
 
9
  os.environ["WANDB_DISABLED"] = "true"
10
 
 
 
 
 
 
 
 
11
  model_file_name = "xgb_reg.pkl"
12
  vectorizer_file_name = 'vectorizer.pk'
13
 
 
14
  # load
15
  xgb_model_loaded = pickle.load(open(model_file_name, "rb"))
16
  vectorizer_loaded = pickle.load(open(vectorizer_file_name, "rb"))
17
 
18
- # predict
19
  def predict_sentiment(predict_texts):
20
- predictions_loaded = xgb_model_loaded.predict(vectorizer_loaded.transform(predict_texts))
21
- return predictions_loaded
22
- #le.inverse_transform(predictions_loaded)
23
 
24
 
25
  interface = gr.Interface(
26
  fn=predict_sentiment,
27
  inputs='text',
28
  outputs=['text'],
29
- title='Croatian Movie reviews Sentiment Analysis',
30
  examples= ["Volim kavu","Ne volim kavu"],
31
  description='Get the positive/neutral/negative sentiment for the given input.'
32
  )
33
 
34
- interface.launch(inline = False)
 
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.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)