jayasuriyaK commited on
Commit
c2770a4
1 Parent(s): c2429ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -1,14 +1,17 @@
1
  #run the app
2
  #python -m streamlit run d:/NSFW/Project/test1.py
3
  import torch
4
- from transformers import BertTokenizer, BertForSequenceClassification
 
5
  import math, keras_ocr
6
  # Initialize pipeline
7
  pipeline = None
8
- tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
9
- model_2 = BertForSequenceClassification.from_pretrained("CustomModel")
10
-
11
- model_2.to('cpu')
 
 
12
  import streamlit as st
13
 
14
  def get_distance(predictions):
@@ -102,14 +105,17 @@ if uploaded_file is not None:
102
  sentance = ' '.join(ordered_preds)
103
  #st.write(sentance)
104
 
105
- text =sentance
106
  print(text)
107
- inputs = tokenizer(text,padding = True, truncation = True, return_tensors='pt').to('cpu')
108
  outputs = model_2(**inputs)
109
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
110
- predictions = predictions.cpu().detach().numpy()
 
 
 
111
  print(predictions[0][0],predictions[0][1])
112
- if predictions[0][0]>predictions[0][1]:
113
  print('safe')
114
  st.write('Safe for Work')
115
  else:
 
1
  #run the app
2
  #python -m streamlit run d:/NSFW/Project/test1.py
3
  import torch
4
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
+ #from transformers import BertTokenizer, BertForSequenceClassification
6
  import math, keras_ocr
7
  # Initialize pipeline
8
  pipeline = None
9
+ model_path="NSFW_text_classifier"
10
+ #tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
11
+ #model_2 = BertForSequenceClassification.from_pretrained("CustomModel")
12
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
13
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
14
+ #model_2.to('cpu')
15
  import streamlit as st
16
 
17
  def get_distance(predictions):
 
105
  sentance = ' '.join(ordered_preds)
106
  #st.write(sentance)
107
 
108
+ input_text =sentance
109
  print(text)
110
+ """inputs = tokenizer(text,padding = True, truncation = True, return_tensors='pt').to('cpu')
111
  outputs = model_2(**inputs)
112
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
113
+ predictions = predictions.cpu().detach().numpy()"""
114
+ inputs = tokenizer(input_text, return_tensors="pt")
115
+ outputs = model(**inputs)
116
+ predictions = outputs.logits.softmax(dim=-1)
117
  print(predictions[0][0],predictions[0][1])
118
+ if predictions[0][1]>predictions[0][0]:
119
  print('safe')
120
  st.write('Safe for Work')
121
  else: