PraneshJs commited on
Commit
cf53d89
Β·
verified Β·
1 Parent(s): 860f7ba

Update gri.py

Browse files
Files changed (1) hide show
  1. gri.py +14 -3
gri.py CHANGED
@@ -3,10 +3,21 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  from deep_translator import GoogleTranslator
4
  from langdetect import detect
5
  import torch
 
6
 
 
7
  MODEL_DIR = "model"
8
- tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
9
- model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR, from_safetensors=True)
 
 
 
 
 
 
 
 
 
10
  emotion_labels = {
11
  0: "Negative πŸ˜•",
12
  1: "Neutral 😐",
@@ -39,4 +50,4 @@ iface = gr.Interface(
39
  )
40
 
41
  if __name__ == "__main__":
42
- iface.launch(share = True) # Set share=True to allow public access
 
3
  from deep_translator import GoogleTranslator
4
  from langdetect import detect
5
  import torch
6
+ import os
7
 
8
+ MODEL_NAME = "cardiffnlp/twitter-roberta-base-sentiment"
9
  MODEL_DIR = "model"
10
+
11
+ # Download model if not present
12
+ if not os.path.exists(MODEL_DIR) or not os.listdir(MODEL_DIR):
13
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
14
+ tokenizer.save_pretrained(MODEL_DIR)
15
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
16
+ model.save_pretrained(MODEL_DIR)
17
+ else:
18
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
19
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
20
+
21
  emotion_labels = {
22
  0: "Negative πŸ˜•",
23
  1: "Neutral 😐",
 
50
  )
51
 
52
  if __name__ == "__main__":
53
+ iface.launch(share=False)