susanesho commited on
Commit
ce799e4
1 Parent(s): 9533de1

Add application files

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy
3
+ from scipy.special import softmax
4
+
5
+ from transformers import (
6
+ AutoTokenizer,
7
+ AutoConfig,
8
+ AutoModelForSequenceClassification
9
+ )
10
+
11
+ model_path = "EmotiScan/amazon-comments-bert"
12
+
13
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
14
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
15
+
16
+ def get_sentiments(text):
17
+
18
+ encoded_input = tokenizer(text, return_tensors='pt')
19
+ output = model(**encoded_input)
20
+
21
+ scores = output[0][0].detach().numpy()
22
+ scores = softmax(scores)
23
+
24
+ labels = ['Terrible', 'Bad', 'Good', 'Very Good', 'Excellent']
25
+ scores = {l:float(s) for (l,s) in zip(labels, scores) }
26
+
27
+ return scores
28
+
29
+ try_out = gr.Interface(
30
+ fn=get_sentiments,
31
+ inputs=gr.Textbox(placeholder="Input the product review"),
32
+ outputs=gr.Textbox(),
33
+ # interpretation="default",
34
+ css= "body {background-color: black}"
35
+ )
36
+
37
+ try_out.launch()
38
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ scipy
4
+ gradio