Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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=
|
| 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"],
|