barbieheimer commited on
Commit
7fc03a0
•
1 Parent(s): 893b93a

Update app.py

Browse files

The real deal!!! YAAAAY TRIAL AND ERROR.

Files changed (1) hide show
  1. app.py +50 -0
app.py CHANGED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
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"],
21
+ "Surprise 😲": pred[2]["score"],
22
+ "Sadness 😭": pred[3]["score"],
23
+ }
24
+ return result
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",
34
+ label="Input Text",
35
+ ),
36
+ outputs="label",
37
+ title="Emotion Classification",
38
+ examples=[
39
+ ["The movie was a bummer."],
40
+ ["I cannot wait to watch all these movies!"],
41
+ ["The ending of the movie really irks me, gives me the ick fr."],
42
+ ["The protagonist seems to have a lot of hope...."]
43
+ ],
44
+ )
45
+
46
+ iface.launch()
47
+
48
+
49
+ if __name__ == "__main__":
50
+ main()