Spaces:
Runtime error
Runtime error
barbieheimer
commited on
Commit
•
1218f5b
1
Parent(s):
edd2ff9
COMMENTING. HEHEHE
Browse filesAdding comments for future ease.
app.py
CHANGED
@@ -3,18 +3,18 @@ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipe
|
|
3 |
|
4 |
|
5 |
class EmotionClassifier:
|
6 |
-
def __init__(self):
|
7 |
-
self.model = AutoModelForSequenceClassification.from_pretrained("barbieheimer/MND_TweetEvalBert_model")
|
8 |
-
self.tokenizer = AutoTokenizer.from_pretrained("barbieheimer/MND_TweetEvalBert_model")
|
9 |
self.pipeline = pipeline(
|
10 |
-
"text-classification",
|
11 |
model=self.model,
|
12 |
tokenizer=self.tokenizer,
|
13 |
-
return_all_scores=True,
|
14 |
)
|
15 |
-
|
16 |
-
def predict(self, input_text: str):
|
17 |
-
pred = self.pipeline(input_text)[0]
|
18 |
result = {
|
19 |
"Anger 😠": pred[0]["score"],
|
20 |
"Joy 😂": pred[1]["score"],
|
@@ -25,9 +25,10 @@ class EmotionClassifier:
|
|
25 |
|
26 |
|
27 |
def main():
|
|
|
28 |
model = EmotionClassifier()
|
29 |
iface = gr.Interface(
|
30 |
-
fn=model.predict,
|
31 |
inputs=gr.inputs.Textbox(
|
32 |
lines=3,
|
33 |
placeholder="Type a phrase that has some emotion",
|
|
|
3 |
|
4 |
|
5 |
class EmotionClassifier:
|
6 |
+
def __init__(self): # since we have defined the models below, this class will call itself.
|
7 |
+
self.model = AutoModelForSequenceClassification.from_pretrained("barbieheimer/MND_TweetEvalBert_model") # specify the model from repo.
|
8 |
+
self.tokenizer = AutoTokenizer.from_pretrained("barbieheimer/MND_TweetEvalBert_model") #need to spicify the tokeniser from repo too
|
9 |
self.pipeline = pipeline(
|
10 |
+
"text-classification", # specify pipeline task here.
|
11 |
model=self.model,
|
12 |
tokenizer=self.tokenizer,
|
13 |
+
return_all_scores=True, # so that all emotional scores are displayed.
|
14 |
)
|
15 |
+
# creating a prediction definition.
|
16 |
+
def predict(self, input_text: str): # defining what the output will look like.
|
17 |
+
pred = self.pipeline(input_text)[0] # processing text input.
|
18 |
result = {
|
19 |
"Anger 😠": pred[0]["score"],
|
20 |
"Joy 😂": pred[1]["score"],
|
|
|
25 |
|
26 |
|
27 |
def main():
|
28 |
+
# call the emotionclassifier class to use our model, and now we can use the gradio UI.
|
29 |
model = EmotionClassifier()
|
30 |
iface = gr.Interface(
|
31 |
+
fn=model.predict, # using the model to predict
|
32 |
inputs=gr.inputs.Textbox(
|
33 |
lines=3,
|
34 |
placeholder="Type a phrase that has some emotion",
|