File size: 1,611 Bytes
1594847
 
 
 
86caae9
a6fc531
 
 
 
 
 
1594847
 
 
a6fc531
 
 
 
 
 
 
 
 
 
 
 
 
 
1594847
 
a6fc531
1594847
a6fc531
 
1594847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
import pytesseract
from PIL import Image
import cv2
import numpy as np
import os
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import gradio as gr
import torch

def ocr_image(image):
    """Perform OCR on an image and classify logo."""
    # Convert image to grayscale
    # gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # # Perform OCR on the grayscale image
    # text = pytesseract.image_to_string(gray)

    # # Classify logo based on presence of space in 'amazonbasics'
  
    ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
    result = ocr.ocr(image, cls=True)[0]
    # image = Image.open(img_path).convert('RGB')
    boxes = [line[0] for line in result]
    txts = [line[1][0] for line in result]
    text =  '\n'.join(txts)
    
    if 'amazon basics' in text.lower():
        return 'New Logo'
    elif 'amazonbasics' in text.lower():
        return 'Old Logo'
    else:
        return "NA"

# Streamlit interface
st.title('Logo Classifier')

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image.', use_column_width=True)
    st.write("")
    st.write("Classifying...")

    # Convert the image to an OpenCV array (numpy array)
    open_cv_image = np.array(image)
    # Convert RGB to BGR 
    open_cv_image = open_cv_image[:, :, ::-1].copy()

    # Perform OCR and classify logo
    logo_type = ocr_image(open_cv_image)

    # Display classification result
    st.write(f"Logo Type: {logo_type}")