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)