forked from PradipNichite/Youtube-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fa7cf7
commit b1feaab
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3.9.10 | ||
|
||
WORKDIR /app | ||
|
||
COPY ./requirements.txt requirements.txt | ||
COPY ./app.py app.py | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
EXPOSE 8501 | ||
|
||
CMD streamlit run app.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import streamlit as st | ||
import numpy as np | ||
from transformers import BertTokenizer, BertForSequenceClassification | ||
import torch | ||
|
||
@st.cache(allow_output_mutation=True) | ||
def get_model(): | ||
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') | ||
model = BertForSequenceClassification.from_pretrained("pnichite/YTFineTuneBert") | ||
return tokenizer,model | ||
|
||
|
||
tokenizer,model = get_model() | ||
|
||
user_input = st.text_area('Enter Text to Analyze') | ||
button = st.button("Analyze") | ||
|
||
d = { | ||
|
||
1:'Toxic', | ||
0:'Non Toxic' | ||
} | ||
|
||
if user_input and button : | ||
test_sample = tokenizer([user_input], padding=True, truncation=True, max_length=512,return_tensors='pt') | ||
# test_sample | ||
output = model(**test_sample) | ||
# st.write("Logits: ",output.logits) | ||
y_pred = np.argmax(output.logits.detach().numpy(),axis=1) | ||
st.write("Prediction: ",d[y_pred[0]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
streamlit | ||
torch | ||
transformers |