DAI_OBJ / app.py
HamzaFarhan's picture
yolov
bee695e
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
# %% auto 0
__all__ = ['model', 'imgs', 'examples', 'iface', 'predict']
# %% app.ipynb 1
import gradio as gr
from dreamai.core import *
from dreamai.vision import *
from dreamai.imports import *
from dreamai_obj.core import *
# %% app.ipynb 2
model = obj_model()
def predict(img, box_x=0, box_y=0, box_w=0.5, box_h=0.5, color='red'):
box_args = {'avoidance_x': box_x, 'avoidance_y': box_y}
box_args['avoidance_w'] = min(box_w, 0.99)
box_args['avoidance_h'] = min(box_h, 0.99)
return detect_obstacles_3(model, img, alert=True, obj_h_limit=None, show=True,
box_thicknes=2, conf=0.5, overlap_limit=0, color=color, **box_args)[0]
imgs = get_image_files('imgs')
examples = [[imgs[0], 0, 0, 0.4, 0.225],[imgs[1], 0, 0.8, 0.225, 0.5]]
iface = gr.Interface(fn=predict, title='DreamAI Object Detection',
description='Use dreamai with yolov5 to detect all obstacles in a certain area of an image.',
outputs=gr.Image(type="numpy"), examples=examples,
inputs=[gr.Image(type="numpy"),
gr.Slider(0, 1., 0.5, step=0.025, label='Box Top X (Relative)'),
gr.Slider(0, 1., 0.5, step=0.025, label='Box Top Y (Relative)'),
gr.Slider(0, 1., 0.5, step=0.025, label='Box Width (Relative)'),
gr.Slider(0, 1., 0.5, step=0.025, label='Box Height (Relative)'),
gr.Dropdown(['red', 'green', 'blue', 'yellow'], label='Color', value='red')
],
)
iface.launch()