Di12 commited on
Commit
58f129d
·
1 Parent(s): b41187e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -9,6 +9,7 @@ import unicodedata
9
  import re
10
  from tqdm import tqdm
11
  import gradio as gr
 
12
 
13
  # Device configuration: consistent device for model and tensors
14
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -114,9 +115,12 @@ class RNN(nn.Module):
114
  h = h[-1]
115
  return self.fc(self.dropout(h))
116
 
 
 
 
117
  # Load pretrained embeddings and build vocab
118
  word_embedding = vocab.Vectors(
119
- name='/content/drive/MyDrive/Colab Notebooks/Data/Sentiment Analysis/vi_word2vec.txt',
120
  unk_init=torch.Tensor.normal_
121
  )
122
  vocab = Vocabulary()
@@ -142,7 +146,7 @@ def load_model(path: str):
142
  model.eval()
143
  return model
144
 
145
- model = load_model('/content/drive/MyDrive/Colab Notebooks/Data/Sentiment Analysis/model.pt')
146
 
147
  # Prediction helper
148
  def predict_sentiment(model, sentence, vocab, label_mapping=None):
 
9
  import re
10
  from tqdm import tqdm
11
  import gradio as gr
12
+ from huggingface_hub import hf_hub_download
13
 
14
  # Device configuration: consistent device for model and tensors
15
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
115
  h = h[-1]
116
  return self.fc(self.dropout(h))
117
 
118
+ model_path = hf_hub_download(repo_id="Di12/sentiment_analysis", filename="model.pt")
119
+ embedding_path = hf_hub_download(repo_id="Di12/sentiment_analysis", filename="vi_word2vec.txt")
120
+
121
  # Load pretrained embeddings and build vocab
122
  word_embedding = vocab.Vectors(
123
+ name=embedding_path,
124
  unk_init=torch.Tensor.normal_
125
  )
126
  vocab = Vocabulary()
 
146
  model.eval()
147
  return model
148
 
149
+ model = load_model(model_path)
150
 
151
  # Prediction helper
152
  def predict_sentiment(model, sentence, vocab, label_mapping=None):