CoolFace
Apppublic

devwildlifeai/wildlife_watcher_annotation_app_deva

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
archive.py144 linesDownload Raw Back to root
1"""2current_file_path = Path(__file__).resolve()3relative_path = "path/to/file"4absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()5 6 7def get_file_content(file):8    return (file,)9 10 11with gr.Blocks() as demo:12    gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')13    submit_btn = gr.Button("Select")14    with gr.Row():15        file = gr.FileExplorer(16            glob="**/components/*.py",17            # value=["themes/utils"],18            root_dir=absolute_path,19            ignore_glob="**/__init__.py",20        )21 22        file2 = gr.FileExplorer(23            glob="**/components/**/*.py",24            root_dir=absolute_path,25            ignore_glob="**/__init__.py",26        )27    submit_btn.click(lambda x: x, file, file2)28 29    gr.Markdown("---")30    gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')31    with gr.Group():32        with gr.Row():33            file_3 = gr.FileExplorer(34                scale=1,35                glob="**/components/**/*.py",36                value=["themes/utils"],37                file_count="single",38                root_dir=absolute_path,39                ignore_glob="**/__init__.py",40                elem_id="file",41            )42 43            code = gr.Code(lines=30, scale=2, language="python")44 45    file_3.change(get_file_content, file_3, code)46 47if __name__ == "__main__":48    demo.launch()49"""50 51""" Version 152def display_name_files(_folder_path):53    return f"{[img_name for img_name in os.listdir(_folder_path)]} \n"54 55 56def on_browse(data_type):57    root = Tk()58    root.attributes("-topmost", True)59    root.withdraw()60    if data_type == "Files":61        filenames = filedialog.askopenfilenames()62        if len(filenames) > 0:63            root.destroy()64            return str(filenames)65        else:66            filename = "Files not seleceted"67            root.destroy()68            return str(filename)69 70    elif data_type == "Folder":71        filename = filedialog.askdirectory()72        print(filename)73        print(type(filename))74        if filename:75            if os.path.isdir(filename):76                root.destroy()77                return str("\n".join(os.listdir(filename)))78                # return str(filename)79            else:80                root.destroy()81                return str(filename)82        else:83            filename = "Folder not seleceted"84            root.destroy()85            return str(filename)86 87 88def main():89    with gr.Blocks() as demo:90        data_type = gr.Radio(91            choices=["Files", "Folder"], value="Files", label="Offline data type"92        )93        input_path = gr.Textbox(94            label="Select Multiple videos", scale=5, interactive=False95        )96        image_browse_btn = gr.Button("Browse", min_width=1)97        image_browse_btn.click(98            on_browse, inputs=data_type, outputs=input_path, show_progress="hidden"99        )100    return demo101 102 103demo = main()104demo.launch(inbrowser=True)105"""106 107'''108def get_image_name(_image):109    if _image.any():110        # print(type(_image))111        output_info = f"""112        Image shape: 113        {_image.shape}114        """115        return output_info116    else:117        return "No file uploaded"118 119 120def list_images(dir):121    return [d.name for d in dir]122 123 124with gr.Blocks() as interface:125    gr.Markdown("Import your image and then click the button to see the output.")126    with gr.Row():127        input_img = gr.Image(label="Input Image", height=500, width=500)128        # output_img = gr.Image(label="Recognized Image")129        # display_df = gr.DataFrame(export_results)130        output_info = gr.Textbox()131        # export_info = gr.Textbox()132    labelling_btn = gr.Button("Apply Species Recognition")133    # export_btn = gr.Button("Export result as a CSV")134    labelling_btn.click(fn=get_image_name, inputs=input_img, outputs=[output_info])135    # export_btn.click(fn=export_results, inputs=input_img, outputs=[export_info])136 137    with gr.Row():138        gr.Dataframe(pd.DataFrame({"col1": [1, 2], "col2": [3, 4]}))139 140# Launch the app141if __name__ == "__main__":142    interface.launch()143'''144