ngamulin commited on
Commit
bd4ca57
·
verified ·
1 Parent(s): 276b006

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -72,18 +72,18 @@ model.eval()
72
 
73
  def predict(text):
74
  if not text.strip():
75
- return {}
76
  ids = [word2id.get(t, 1) for t in text.lower().split()][:max_len]
77
  ids += [0] * (max_len - len(ids))
78
  with torch.no_grad():
79
  probs = torch.softmax(model(torch.tensor(ids).unsqueeze(0)), dim=1)[0]
80
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
81
 
82
 
83
  demo = gr.Interface(
84
  fn=predict,
85
  inputs=gr.Textbox(lines=3, placeholder="Unesi tekst...", label="Text"),
86
- outputs=gr.Label(num_top_classes=5, label="Sentiment"),
87
  title="Sentiment Analysis (BiLSTM, fastText hr)",
88
  description="Five-class sentiment: mixed, negative, neutral, positive, sarcastic.",
89
  examples=["Volim kavu", "Ovo je grozno i mrzim ga", "Dan je bio ok"],
 
72
 
73
  def predict(text):
74
  if not text.strip():
75
+ return ""
76
  ids = [word2id.get(t, 1) for t in text.lower().split()][:max_len]
77
  ids += [0] * (max_len - len(ids))
78
  with torch.no_grad():
79
  probs = torch.softmax(model(torch.tensor(ids).unsqueeze(0)), dim=1)[0]
80
+ return labels[int(probs.argmax())]
81
 
82
 
83
  demo = gr.Interface(
84
  fn=predict,
85
  inputs=gr.Textbox(lines=3, placeholder="Unesi tekst...", label="Text"),
86
+ outputs=gr.Label(num_top_classes=1, label="Sentiment"),
87
  title="Sentiment Analysis (BiLSTM, fastText hr)",
88
  description="Five-class sentiment: mixed, negative, neutral, positive, sarcastic.",
89
  examples=["Volim kavu", "Ovo je grozno i mrzim ga", "Dan je bio ok"],