Spaces:
Runtime error
Runtime error
File size: 1,691 Bytes
ce11593 |
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 easyocr
from gradio_client import Client, handle_file
import pandas as pd
import gradio as gr
clientImg = Client("dj-dawgs-ipd/IPD-Image-ViT-Finetune")
clientEngText = Client("dj-dawgs-ipd/IPD-Text-English-Finetune")
clientHingText = Client("dj-dawgs-ipd/IPD-Text-Hinglish")
profanity_df = pd.read_csv('Hinglish_Profanity_List.csv' , encoding = 'utf-8')
profanity_hn = profanity_df['profanity_hn']
def extract_text(image):
reader = easyocr.Reader(['en'])
data = [result[1] for result in reader.readtext(image)]
return ' '.join([l for l in data])
def predict(image):
imgResult = clientImg.predict(
image=handle_file(image),
api_name="/predict"
)
if float(imgResult[1]['label']) > 0.95:
return ["hate" , imgResult[0]]
else:
ocr_text = extract_text(image)
engResult = clientEngText.predict(
text=ocr_text,
api_name="/classify_text"
)
hingResult = clientHingText.predict(
text=ocr_text,
api_name="/predict"
)
if engResult[0] == "NEITHER" or hingResult[0] == "NAG":
return ["not_hate" , None]
else:
return ["hate" , None]
iface = gr.Interface(fn=predict,
inputs = gr.Image(type='pil'),
outputs=[gr.Label(label = "Class") , gr.Label(label = "Hate Symbol(if any)")],
title = "Hate Speech Detection in Image",
description = "Detect hateful symbols or text in Image"
)
if __name__ == "__main__":
iface.launch()
|