import os import subprocess import glob import gradio as gr from gradio.components import Gallery, Video, Textbox, Radio from classificatsion_video_demo import process def get_car_numbers(result_folder): # change current working directory to binare/linux/mu gdfg current_dir = os.getcwd() os.chdir("binaries/linux/x86_64") # construct and run the command # command = "python ../../../python/setup.py build_ext --inplace -v" # process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE) command = "PYTHONPATH=$PYTHONPATH:.:../../../python LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH python ../../../scripts/alpr/license_plate_recognizer.py --image ../../../"+result_folder+" --assets ../../../assets" process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE) # send newline character to standard input process.communicate(input='\n'.encode()) # wait for the subprocess to exit process.wait() os.chdir(current_dir) return 0 def predict(video_path, radio): """ Gradio interface orqali yuklab olingan videodan problem framelarni ajratib olinadi va resultat sifatida Galleryga chiqariladi :param video_path: :return: file """ # Your image processing code here # print(video_path) print("radio: ",radio,type(radio)) which_model=True if radio =="128-1": which_model=False _path_RES = "assets/result_imgs" images_res = glob.glob(f'{_path_RES}/*.jpg') for image in images_res: os.remove(image) _path = "assets/images" images_res = glob.glob(f'{_path}/*.jpg') for image in images_res: os.remove(image) problem, good, result = process(video_path,which_model) get_car_numbers(_path) images = glob.glob(f'{_path_RES}/*.jpg') # # selected_images = [images[0],images[len(images)//2],images[-1]] res_txt = f"{problem}/{problem+good}" return res_txt,images # return 0, 0, 0, images my_example = [ ['video/vid_39_1284-2_1202.mp4'] # ['video/vid_39_1284-2_1174.mp4'] ] my_title = "To’xtash chizig’i bosilgan kadrlarni topish (modda:128-4)" my_description = """ """ all_frame = Textbox(label="Topilgan kadrlar / Umumiy kadrlar") problem_frames = Gallery(label="Muammoli kadrlar", elem_id="gallery").style( grid_cols=[3], height="auto" ) input_video = Video(label="Kiruvchi video") # Create input video component radio = Radio(choices=["128-1", "128-4"], label="Qoida buzilishi modda boyicha") gr.Interface(fn=predict, inputs=[input_video, radio], outputs=[all_frame,problem_frames], title=my_title, examples=my_example, description=my_description).launch()