File size: 2,727 Bytes
908e980
 
 
 
adaf02d
908e980
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adaf02d
908e980
 
 
 
 
 
 
adaf02d
 
 
 
8affd3f
 
 
 
 
 
 
908e980
adaf02d
be54c3d
8affd3f
 
908e980
b0fe78c
 
908e980
 
 
 
be54c3d
908e980
 
 
b0fe78c
 
908e980
b0fe78c
 
 
 
adaf02d
908e980
 
adaf02d
908e980
adaf02d
b0fe78c
908e980
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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()