MattekJenduls commited on
Commit
fd31e5f
β€’
1 Parent(s): 28e566d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -1,36 +1,34 @@
1
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
 
3
- download = False
4
- save_model_locally= False
5
- if download:
6
- tokenizer = AutoTokenizer.from_pretrained("MilaNLProc/feel-it-italian-sentiment", cache_dir="data/")
7
- model_sent = AutoModelForSequenceClassification.from_pretrained("MilaNLProc/feel-it-italian-sentiment", cache_dir="data/")
8
- model_sent.eval()
9
- tokenizer_emo = AutoTokenizer.from_pretrained("MilaNLProc/feel-it-italian-emotion", cache_dir="data/")
10
- model_emo = AutoModelForSequenceClassification.from_pretrained("MilaNLProc/feel-it-italian-emotion", cache_dir="data/")
11
- model_emo.eval()
12
- if save_model_locally:
13
- model_sent.save_pretrained('./local_models/sentiment_ITA')
14
- tokenizer.save_pretrained('./local_models/sentiment_ITA')
15
- model_emo.save_pretrained('./local_models/emotion_ITA')
16
- tokenizer_emo.save_pretrained('./local_models/emotion_ITA')
17
- else:
18
- tokenizer = AutoTokenizer.from_pretrained("./local_models/sentiment_ITA/")
19
- model_sent = AutoModelForSequenceClassification.from_pretrained("./local_models/sentiment_ITA/", num_labels=2)
20
- model_sent.eval()
21
 
22
- tokenizer_emo = AutoTokenizer.from_pretrained("./local_models/emotion_ITA/")
23
- model_emo = AutoModelForSequenceClassification.from_pretrained("./local_models/emotion_ITA/", num_labels=4)
24
- model_emo.eval()
25
 
26
 
27
- #%%generator_sent
28
 
29
  from transformers import pipeline
30
- import re
31
-
32
- generator_sent = pipeline(task="text-classification", model_sent=model_sent, tokenizer=tokenizer, return_all_scores =True)
33
- generator_emo = pipeline(task="text-classification", model_sent=model_emo, tokenizer=tokenizer_emo, return_all_scores =True)
34
 
35
  def sentiment_emoji(input_abs):
36
 
@@ -38,6 +36,7 @@ def sentiment_emoji(input_abs):
38
  return "πŸ€·β€β™‚οΈ"
39
 
40
  res = generator_sent(input_abs)[0]
 
41
  res = {res[x]["label"]: res[x]["score"] for x in range(len(res))}
42
  res["πŸ™‚ positive"] = res.pop("positive")
43
  res["πŸ™ negative"] = res.pop("negative")
 
1
+ # from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
 
3
+ # download = False
4
+ # save_model_locally= False
5
+ # if download:
6
+ # tokenizer = AutoTokenizer.from_pretrained("MilaNLProc/feel-it-italian-sentiment", cache_dir="data/")
7
+ # model_sent = AutoModelForSequenceClassification.from_pretrained("MilaNLProc/feel-it-italian-sentiment", cache_dir="data/")
8
+ # model_sent.eval()
9
+ # tokenizer_emo = AutoTokenizer.from_pretrained("MilaNLProc/feel-it-italian-emotion", cache_dir="data/")
10
+ # model_emo = AutoModelForSequenceClassification.from_pretrained("MilaNLProc/feel-it-italian-emotion", cache_dir="data/")
11
+ # model_emo.eval()
12
+ # if save_model_locally:
13
+ # model_sent.save_pretrained('./local_models/sentiment_ITA')
14
+ # tokenizer.save_pretrained('./local_models/sentiment_ITA')
15
+ # model_emo.save_pretrained('./local_models/emotion_ITA')
16
+ # tokenizer_emo.save_pretrained('./local_models/emotion_ITA')
17
+ # else:
18
+ # tokenizer = AutoTokenizer.from_pretrained("./local_models/sentiment_ITA/")
19
+ # model_sent = AutoModelForSequenceClassification.from_pretrained("./local_models/sentiment_ITA/", num_labels=2)
20
+ # model_sent.eval()
21
 
22
+ # tokenizer_emo = AutoTokenizer.from_pretrained("./local_models/emotion_ITA/")
23
+ # model_emo = AutoModelForSequenceClassification.from_pretrained("./local_models/emotion_ITA/", num_labels=4)
24
+ # model_emo.eval()
25
 
26
 
27
+ # #%%generator_sent
28
 
29
  from transformers import pipeline
30
+ generator_sent = pipeline(task="text-classification", model='./local_models/sentiment_ITA/', top_k=None)
31
+ generator_emo = pipeline(task="text-classification", model='./local_models/emotion_ITA/', top_k=None)
 
 
32
 
33
  def sentiment_emoji(input_abs):
34
 
 
36
  return "πŸ€·β€β™‚οΈ"
37
 
38
  res = generator_sent(input_abs)[0]
39
+ print("res: ", res)
40
  res = {res[x]["label"]: res[x]["score"] for x in range(len(res))}
41
  res["πŸ™‚ positive"] = res.pop("positive")
42
  res["πŸ™ negative"] = res.pop("negative")