lwdragon commited on
Commit
33b9d48
1 Parent(s): 7d6ffc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import math
2
- import zipfile
3
  import numpy as np
4
 
5
  import gradio as gr
@@ -16,7 +15,7 @@ from mindspore.common.initializer import Uniform, HeUniform
16
  def load_glove():
17
  embeddings = []
18
  tokens = []
19
- with open("./lstm/glove.6B.100d.txt", encoding='utf-8') as gf:
20
  for glove in gf:
21
  word, embedding = glove.split(maxsplit=1)
22
  tokens.append(word)
@@ -82,14 +81,13 @@ def prefict_emotion(sentence):
82
  net = RNN(embeddings, hidden_size, output_size, num_layers, bidirectional, dropout, pad_idx)
83
 
84
  # 将模型参数存入parameter的字典中
85
- param_dict = load_checkpoint("./lstm/sentiment-analysis.ckpt")
86
 
87
  # 将参数加载到网络中
88
  load_param_into_net(net, param_dict)
89
- model = Model(net)
90
 
91
  # 预测
92
- pred = predict_sentiment(model, vocab, sentence)
93
  result = {
94
  "Positive 🙂": pred,
95
  "Negative 🙃": 1-pred,
 
1
  import math
 
2
  import numpy as np
3
 
4
  import gradio as gr
 
15
  def load_glove():
16
  embeddings = []
17
  tokens = []
18
+ with open("./glove.6B.100d.txt", encoding='utf-8') as gf:
19
  for glove in gf:
20
  word, embedding = glove.split(maxsplit=1)
21
  tokens.append(word)
 
81
  net = RNN(embeddings, hidden_size, output_size, num_layers, bidirectional, dropout, pad_idx)
82
 
83
  # 将模型参数存入parameter的字典中
84
+ param_dict = load_checkpoint("./sentiment-analysis.ckpt")
85
 
86
  # 将参数加载到网络中
87
  load_param_into_net(net, param_dict)
 
88
 
89
  # 预测
90
+ pred = predict_sentiment(net, vocab, sentence)
91
  result = {
92
  "Positive 🙂": pred,
93
  "Negative 🙃": 1-pred,