joaopdrm commited on
Commit
2925e7b
1 Parent(s): fc8d34d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -4
app.py CHANGED
@@ -1,7 +1,40 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
3
 
 
 
4
 
5
+ class Emotionclass:
6
+ def __init__(self, model: str):
7
+ self.model = AutoModelForSequenceClassification.from_pretrained(model)
8
+ self.pipeline = pipeline(
9
+ "text-classification",
10
+ model=self.model,
11
+ return_all_scores=True,
12
+ )
13
+
14
+ def predict(self, input: str):
15
+ output = self.pipeline(input)[0]
16
+ result = {
17
+ "sad": output[0]["score"],
18
+ "joy": output[1]["score"],
19
+ "love": output[2]["score"],
20
+ "anger": output[3]["score"],
21
+ "fear": output[4]["score"],
22
+ "surprise": output[5]["score"],
23
+ }
24
+ return result
25
+
26
+
27
+ def main():
28
+ model = Emotionclass("bhadresh-savani/bert-base-uncased-emotion")
29
+ iface = gr.Interface(
30
+ fn=model.predict,
31
+ inputs="text",
32
+ outputs=["text"],
33
+ title="Sentiment Classification",
34
+ )
35
+
36
+ iface.launch()
37
+
38
+
39
+ if __name__ == "__main__":
40
+ main()