Reacher's picture
ASL app
7881e86
raw
history blame
1.48 kB
import gradio as gr
import cv2
import requests
from ultralytics import YOLO
model = YOLO('best.pt')
path = [['image.jpg']]
classes = ['ain', 'al', 'aleff','bb','dal','dha','dhad','fa','gaaf','ghain','ha','haa','jeem','kaaf','khaa','la','laam',
'meem','nun','ra','saad','seen','sheen','ta','taa','thaa','thal','toot','waw','ya','yaa','zay']
TargetMapper = dict(zip(range(32),classes))
def show_preds_image(image_path):
image = cv2.imread(image_path)
outputs = model.predict(source=image_path)
results = outputs[0].cpu().numpy()
for i, det in enumerate(results.boxes.xyxy):
cls = TargetMapper[results.boxes.cls[0]]
print(cls)
cv2.rectangle(
image,
(int(det[0]), int(det[1])),
(int(det[2]), int(det[3])),
color=(0, 0, 255),
thickness=2,
lineType=cv2.LINE_AA
)
cv2.putText(image, cls, (int(det[0]), int(det[1])-10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36,255,12), 2)
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#image = cv2.imwrite('output.jpg', show_preds_image(path))
inputs_image = [
gr.components.Image(type="filepath", label="Input Image"),
]
outputs_image = [
gr.components.Image(type="numpy", label="Output Image"),
]
interface_image = gr.Interface(
fn=show_preds_image,
inputs=inputs_image,
outputs=outputs_image,
title="Arab Sign Language Detection app",
examples=path,
cache_examples=False,
).launch()