Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
|
4 |
+
model = torch.load("./model.pt")
|
5 |
+
st.title("Analisis de Sentimientos")
|
6 |
+
txt = st.text_area(label="Please write what you want to analyze...")
|
7 |
+
|
8 |
+
def run_sentiment_analysis (txt) :
|
9 |
+
THRESHOLD = 0.5
|
10 |
+
|
11 |
+
encoding = tokenizer.encode_plus(
|
12 |
+
txt,
|
13 |
+
add_special_tokens=True,
|
14 |
+
max_length=512,
|
15 |
+
return_token_type_ids=False,
|
16 |
+
padding="max_length",
|
17 |
+
return_attention_mask=True,
|
18 |
+
return_tensors='pt',
|
19 |
+
)
|
20 |
+
|
21 |
+
_, test_prediction = model(encoding["input_ids"], encoding["attention_mask"])
|
22 |
+
test_prediction = test_prediction.flatten().numpy()
|
23 |
+
|
24 |
+
predictions = []
|
25 |
+
print('-------------------- Predictions ---------------------')
|
26 |
+
|
27 |
+
for label, prediction in zip(LABEL_COLUMNS, test_prediction):
|
28 |
+
if prediction < THRESHOLD:
|
29 |
+
continue
|
30 |
+
predictions.append(" ".join([label,str(prediction)]))
|
31 |
+
return predictions
|
32 |
+
|
33 |
+
predictions = run_sentiment_analysis(txt)
|
34 |
+
for prediction in predictions:
|
35 |
+
st.write(prediction)
|
36 |
+
|