Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,22 +41,26 @@ config.label2id = {"NEGATIVE": 0, "NEUTRAL": 1, "POSITIVE": 2}
|
|
41 |
# creating a function used for gradio app
|
42 |
def sentiment_analysis(text):
|
43 |
|
|
|
|
|
|
|
44 |
# Encode the text using the tokenizer
|
45 |
encoded_input = tokenizer(text, return_tensors='pt')
|
46 |
# Get the output logits from the model
|
47 |
output = model(**encoded_input)
|
48 |
-
|
49 |
# Your code to get the scores for each class
|
50 |
scores = output[0][0].detach().numpy()
|
51 |
scores = softmax(scores)
|
52 |
-
|
53 |
labels = {0: "NEGAITVE", 1: "NEUTRAL", 2: "POSITIVE"}
|
54 |
-
scores = {labels[i] float(s) for i , s in enumerate(scores) }
|
55 |
-
|
56 |
-
|
57 |
# Return the dictionary as the response content
|
58 |
return scores
|
59 |
|
|
|
|
|
60 |
# Create your interface
|
61 |
demo = gr.Interface(
|
62 |
fn=sentiment_analysis,
|
|
|
41 |
# creating a function used for gradio app
|
42 |
def sentiment_analysis(text):
|
43 |
|
44 |
+
# Create a new dictionary
|
45 |
+
scores = {}
|
46 |
+
|
47 |
# Encode the text using the tokenizer
|
48 |
encoded_input = tokenizer(text, return_tensors='pt')
|
49 |
# Get the output logits from the model
|
50 |
output = model(**encoded_input)
|
51 |
+
|
52 |
# Your code to get the scores for each class
|
53 |
scores = output[0][0].detach().numpy()
|
54 |
scores = softmax(scores)
|
55 |
+
|
56 |
labels = {0: "NEGAITVE", 1: "NEUTRAL", 2: "POSITIVE"}
|
57 |
+
scores = {labels[i]: float(s) for i , s in enumerate(scores) }
|
58 |
+
|
|
|
59 |
# Return the dictionary as the response content
|
60 |
return scores
|
61 |
|
62 |
+
|
63 |
+
|
64 |
# Create your interface
|
65 |
demo = gr.Interface(
|
66 |
fn=sentiment_analysis,
|