Spaces:
Sleeping
Sleeping
Pankaj
commited on
Commit
·
a8c5bf0
0
Parent(s):
model and streamlit app push 1
Browse files- nlpproject/app.py +31 -0
- nlpproject/requirements.txt +3 -0
nlpproject/app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
#@st.cache(allow_output_mutation=True)
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def get_model():
|
| 9 |
+
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
| 10 |
+
model = BertForSequenceClassification.from_pretrained("PankajNk/toxichub")
|
| 11 |
+
return tokenizer,model
|
| 12 |
+
|
| 13 |
+
tokenizer,model = get_model()
|
| 14 |
+
|
| 15 |
+
user_input = st.text_area('Enter Test to be Analyze')
|
| 16 |
+
button = st.button("Analyze")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
d ={
|
| 20 |
+
1:'Toxic',
|
| 21 |
+
0:'Non Toxic'
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if user_input and button:
|
| 26 |
+
test_sample = tokenizer([user_input], padding=True, truncation=True, max_length=512,return_tensors='pt')
|
| 27 |
+
outputs = model(**test_sample)
|
| 28 |
+
#predication = torch.nn.functional.softmax(outputs.logits, dim = 1)
|
| 29 |
+
st.write("logits: ", outputs.logits)
|
| 30 |
+
y_predication = np.argmax(outputs.logits.detach().numpy(), axis =1)
|
| 31 |
+
st.write("Predication",d[y_predication[0]])
|
nlpproject/requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
torch
|
| 3 |
+
transformers
|