Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,13 @@ import torch
|
|
| 4 |
from PIL import Image
|
| 5 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def classify_text(text):
|
| 11 |
input_ids = tokenizer(text, return_tensors="pt")
|
|
@@ -20,7 +25,7 @@ uploaded_file = st.file_uploader("Upload Image", type= ['png', 'jpeg', 'jpg'])
|
|
| 20 |
|
| 21 |
if uploaded_file is not None:
|
| 22 |
img = Image.open(uploaded_file)
|
| 23 |
-
ocr_list = [x for x in pytesseract.image_to_string(
|
| 24 |
ocr_class = [classify_text(x) for x in ocr_list]
|
| 25 |
idx = []
|
| 26 |
for i in range(len(ocr_class)):
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 6 |
|
| 7 |
+
st.title(':blue[_SnapCode_]')
|
| 8 |
+
|
| 9 |
+
with st.spinner('Model is loading'):
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained("usvsnsp/code-vs-nl")
|
| 11 |
+
model = AutoModelForSequenceClassification.from_pretrained("usvsnsp/code-vs-nl")
|
| 12 |
+
|
| 13 |
+
st.success('Model loaded')
|
| 14 |
|
| 15 |
def classify_text(text):
|
| 16 |
input_ids = tokenizer(text, return_tensors="pt")
|
|
|
|
| 25 |
|
| 26 |
if uploaded_file is not None:
|
| 27 |
img = Image.open(uploaded_file)
|
| 28 |
+
ocr_list = [x for x in pytesseract.image_to_string(img).split("\n") if x != '']
|
| 29 |
ocr_class = [classify_text(x) for x in ocr_list]
|
| 30 |
idx = []
|
| 31 |
for i in range(len(ocr_class)):
|