Update app.py
Browse files12345676 unmodified lines141516171819202122232425268 unmodified lines35363738394041424344454647484950515253545515 unmodified lines717273747576777879808182838485868788899091929394import gradio as grimport model1 as m1import model2 as m2cars = []lps = []lp_texts = []6 unmodified linescounter = 0return cars[0], lps[0], lp_texts[0]# this is the main function that passes the images to the model 1def model2(image):global lps, lp_texts, counter(lps, lp_texts) = m2.run([image])counter = 0return lps[0], lp_texts[0]# function to go to next detected car licence platedef next_img():global counter8 unmodified linesindex = int(counter % len(cars))return cars[index], lps[index], lp_texts[index]# function to go to next detected licence platedef next_img_lp():global countercounter += 1index = int(counter % len(lps))return lps[index], lp_texts[index]# function to go to prev detected licence platedef prev_img_lp():global countercounter -= 1index = int(counter % len(lps))return lps[index], lp_texts[index]# this code is responcible for the front end part of the pagewith gr.Blocks() as demo:gr.Markdown("## ANPR Project")15 unmodified linessubmit.click(model1, inputs=[img], outputs=[car, lp, lp_text])next.click(next_img, outputs=[car, lp, lp_text])prev.click(prev_img, outputs=[car, lp, lp_text])with gr.Tab("Model 2"):gr.Markdown("Using 2 different ML models")gr.Markdown("YOLOv8m for car dection + easy ocr for text detection")gr.Markdown("YOLOv8m for car dection is trained on a large dataset of 25K training images")img2 = gr.Image(label="Input")submit2 = gr.Button(value="submit")with gr.Row():lp2 = gr.Image(label="Licence Plate")lp_text2 = gr.Text(label="Plate Number")with gr.Row():next2 = gr.Button(value="next")prev2 = gr.Button(value="prev")submit2.click(model2, inputs=[img2], outputs=[lp2, lp_text2])next2.click(next_img_lp, outputs=[lp2, lp_text2])prev2.click(prev_img_lp, outputs=[lp2, lp_text2])demo.launch(share=False)123456 unmodified lines1213141516178 unmodified lines26272829303115 unmodified lines4748495051import gradio as grimport model1 as m1cars = []lps = []lp_texts = []6 unmodified linescounter = 0return cars[0], lps[0], lp_texts[0]# function to go to next detected car licence platedef next_img():global counter8 unmodified linesindex = int(counter % len(cars))return cars[index], lps[index], lp_texts[index]# this code is responcible for the front end part of the pagewith gr.Blocks() as demo:gr.Markdown("## ANPR Project")15 unmodified linessubmit.click(model1, inputs=[img], outputs=[car, lp, lp_text])next.click(next_img, outputs=[car, lp, lp_text])prev.click(prev_img, outputs=[car, lp, lp_text])demo.launch(share=False)
app.py-43