Skip to content

Commit

Permalink
Deploy Transformers on AWS Fargate
Browse files Browse the repository at this point in the history
  • Loading branch information
PradipNichite committed Aug 1, 2022
1 parent 8fa7cf7 commit b1feaab
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions streamlit_fargat/Dockerfile
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
30 changes: 30 additions & 0 deletions streamlit_fargat/app.py
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]])
3 changes: 3 additions & 0 deletions streamlit_fargat/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
streamlit
torch
transformers

0 comments on commit b1feaab

Please sign in to comment.