Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,14 +17,14 @@ def preprocess(text):
|
|
17 |
new_text.append(t)
|
18 |
return " ".join(new_text)
|
19 |
|
20 |
-
def get_top_emojis(text
|
21 |
preprocessed = preprocess(text)
|
22 |
inputs = tokenizer(preprocessed, return_tensors="pt")
|
23 |
preds = model(**inputs).logits
|
24 |
scores = torch.nn.functional.softmax(preds, dim=-1).detach().numpy()
|
25 |
-
sorted_scores = [float(value) for value in np.sort(scores.squeeze())[::-1]]
|
26 |
ranking = np.argsort(scores)
|
27 |
-
ranking = ranking.squeeze()[::-1]
|
28 |
emojis = [model.config.id2label[i] for i in ranking]
|
29 |
return dict(zip(emojis, sorted_scores))
|
30 |
|
@@ -37,7 +37,7 @@ gradio_ui = gr.Interface(
|
|
37 |
gr.inputs.Textbox(lines=3, label="Paste a tweet here"),
|
38 |
],
|
39 |
outputs=[
|
40 |
-
gr.outputs.Label(type="confidences", label=f"Predicted emojis")
|
41 |
],
|
42 |
examples=[
|
43 |
["it's pretty depressing when u hit pan on ur favourite highlighter"],
|
|
|
17 |
new_text.append(t)
|
18 |
return " ".join(new_text)
|
19 |
|
20 |
+
def get_top_emojis(text):
|
21 |
preprocessed = preprocess(text)
|
22 |
inputs = tokenizer(preprocessed, return_tensors="pt")
|
23 |
preds = model(**inputs).logits
|
24 |
scores = torch.nn.functional.softmax(preds, dim=-1).detach().numpy()
|
25 |
+
sorted_scores = [float(value) for value in np.sort(scores.squeeze())[::-1]]
|
26 |
ranking = np.argsort(scores)
|
27 |
+
ranking = ranking.squeeze()[::-1]
|
28 |
emojis = [model.config.id2label[i] for i in ranking]
|
29 |
return dict(zip(emojis, sorted_scores))
|
30 |
|
|
|
37 |
gr.inputs.Textbox(lines=3, label="Paste a tweet here"),
|
38 |
],
|
39 |
outputs=[
|
40 |
+
gr.outputs.Label(type="confidences", label=f"Predicted emojis", num_top_classes=TOP_N)
|
41 |
],
|
42 |
examples=[
|
43 |
["it's pretty depressing when u hit pan on ur favourite highlighter"],
|