Abhilashvj commited on
Commit
a6fc531
1 Parent(s): 7668e6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -3,19 +3,35 @@ import pytesseract
3
  from PIL import Image
4
  import cv2
5
  import numpy as np
 
 
 
 
 
 
6
  def ocr_image(image):
7
  """Perform OCR on an image and classify logo."""
8
  # Convert image to grayscale
9
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
10
-
11
- # Perform OCR on the grayscale image
12
- text = pytesseract.image_to_string(gray)
13
-
14
- # Classify logo based on presence of space in 'amazonbasics'
 
 
 
 
 
 
 
 
15
  if 'amazon basics' in text.lower():
16
  return 'New Logo'
17
- else:
18
  return 'Old Logo'
 
 
19
 
20
  # Streamlit interface
21
  st.title('Logo Classifier')
 
3
  from PIL import Image
4
  import cv2
5
  import numpy as np
6
+ import os
7
+ from paddleocr import PaddleOCR, draw_ocr
8
+ from PIL import Image
9
+ import gradio as gr
10
+ import torch
11
+
12
  def ocr_image(image):
13
  """Perform OCR on an image and classify logo."""
14
  # Convert image to grayscale
15
+ # gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
16
+
17
+ # # Perform OCR on the grayscale image
18
+ # text = pytesseract.image_to_string(gray)
19
+
20
+ # # Classify logo based on presence of space in 'amazonbasics'
21
+
22
+ ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
23
+ result = ocr.ocr(image, cls=True)[0]
24
+ # image = Image.open(img_path).convert('RGB')
25
+ boxes = [line[0] for line in result]
26
+ txts = [line[1][0] for line in result]
27
+ text = '\n'.join(txts)
28
+
29
  if 'amazon basics' in text.lower():
30
  return 'New Logo'
31
+ elif 'amazonbasics' in text.lower():
32
  return 'Old Logo'
33
+ else:
34
+ return "NA"
35
 
36
  # Streamlit interface
37
  st.title('Logo Classifier')