jayasuriyaK commited on
Commit
307a738
·
verified ·
1 Parent(s): 0925337

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,11 +1,10 @@
1
  #run the app
2
  #python -m streamlit run d:/NSFW/Project/test1.py
3
  import torch
4
- import tensorflow as tf
5
  from transformers import BertTokenizer, BertForSequenceClassification
6
  import math, keras_ocr
7
  # Initialize pipeline
8
- pipeline = keras_ocr.pipeline.Pipeline()
9
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
10
  model_2 = BertForSequenceClassification.from_pretrained("CustomModel")
11
 
@@ -70,14 +69,19 @@ st.title("NSFW Content Detector")
70
  # File uploader widget
71
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
72
 
 
 
 
 
 
73
  if uploaded_file is not None:
74
  st.image(uploaded_file, caption='Uploaded Image', width=200)
75
  #st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
76
-
77
- # Read in image
78
  read_image = keras_ocr.tools.read(uploaded_file)
79
 
80
- # prediction_groups is a list of (word, box) tuples
81
  prediction_groups = pipeline.recognize([read_image])
82
  predictions = prediction_groups[0] # extract text list
83
  predictions = get_distance(predictions)
@@ -111,5 +115,4 @@ if uploaded_file is not None:
111
  else:
112
  print('Not safe')
113
  st.write('Not Safe for Work')
114
- pipeline = keras_ocr.pipeline.Pipeline()
115
 
 
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
 
 
69
  # File uploader widget
70
  uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
71
 
72
+ def initialize():
73
+ global pipeline
74
+ if pipeline==None:
75
+ pipeline=keras_ocr.pipeline.Pipeline()
76
+
77
  if uploaded_file is not None:
78
  st.image(uploaded_file, caption='Uploaded Image', width=200)
79
  #st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
80
+ initialize()
81
+ # Read in image
82
  read_image = keras_ocr.tools.read(uploaded_file)
83
 
84
+ # prediction_groups is a list of (word, box) tuples
85
  prediction_groups = pipeline.recognize([read_image])
86
  predictions = prediction_groups[0] # extract text list
87
  predictions = get_distance(predictions)
 
115
  else:
116
  print('Not safe')
117
  st.write('Not Safe for Work')
 
118