File size: 1,561 Bytes
0f6871f
e726c8f
33614e9
e726c8f
33614e9
 
 
e726c8f
c7d838d
 
 
 
 
 
 
 
 
 
e726c8f
 
 
 
33614e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e726c8f
 
 
 
33614e9
e726c8f
33614e9
e726c8f
 
 
 
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
57
58
import os
import gradio as gr
import easyocr
import re
import cv2
import numpy as np
from PIL import Image, ImageDraw

EASY_OCR_DIR = "/app/.EasyOCR"
os.makedirs(EASY_OCR_DIR, exist_ok=True)

reader = easyocr.Reader(
    ["en"],
    gpu=False,
    model_storage_directory=EASY_OCR_DIR,
    user_network_directory=EASY_OCR_DIR,
    download_enabled=True 
)

GAMBLING_KEYWORDS = ["WIN", "BET", "JACKPOT", "CASINO", "SLOT", "999"]

def check_gambling(image):
    img_np = np.array(image)

    results = reader.readtext(img_np)

    detected_texts = []
    gambling_found = False

    img_pil = Image.fromarray(img_np)
    draw = ImageDraw.Draw(img_pil)

    for bbox, text, conf in results:
        text_upper = text.upper()
        detected_texts.append(text_upper)

        if any(kw in text_upper for kw in GAMBLING_KEYWORDS):
            gambling_found = True
            draw.polygon([tuple(point) for point in bbox], outline="red", width=3)
        else:
            draw.polygon([tuple(point) for point in bbox], outline="green", width=2)

    summary = "📝 Detected Texts:\n" + "\n".join(detected_texts)
    summary += f"\n\n🎰 Gambling Detected: {gambling_found}"

    return img_pil, summary

demo = gr.Interface(
    fn=check_gambling,
    inputs=gr.Image(type="pil"),
    outputs=[gr.Image(type="pil"), "text"],
    title="🎰 Gambling Text Detector",
    description="Upload an image. Gambling text is highlighted in **red**, non-gambling text in **green**."
)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)