ashish-001 commited on
Commit
3f6a5b0
·
verified ·
1 Parent(s): cbbc2fc

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import BertTokenizer, BertForSequenceClassification
2
+ import torch
3
+ import streamlit as st
4
+
5
+ tokenizer = BertTokenizer.from_pretrained(
6
+ "ashish-001/Bert-Amazon-review-sentiment-classifier")
7
+ model = BertForSequenceClassification.from_pretrained(
8
+ "ashish-001/Bert-Amazon-review-sentiment-classifier")
9
+
10
+
11
+ def classify_text(text):
12
+ inputs = tokenizer(
13
+ text,
14
+ max_length=256,
15
+ truncation=True,
16
+ padding="max_length",
17
+ return_tensors="pt"
18
+ )
19
+ output = model(**inputs)
20
+ logits = output.logits
21
+ probs = torch.nn.functional.sigmoid(logits)
22
+ return probs
23
+
24
+
25
+ st.title("Amazon Review Sentiment classifier")
26
+ data = st.text_area("Enter or paste a review")
27
+ if st.button('Predict'):
28
+ prediction = classify_text(data)
29
+ st.header(
30
+ f"Negative Confidence: {prediction[0]}, Positive Confidence: {prediction[1]}")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch==2.4.1
2
+ transformers==4.35.2