Spaces:
Sleeping
Sleeping
| #!/usr/bin/python3 | |
| # -*- coding: utf-8 -*- | |
| import gradio as gr | |
| from project_settings import project_path | |
| def get_fs_tab(): | |
| with gr.TabItem("fs"): | |
| with gr.Row(): | |
| with gr.Column(scale=3): | |
| fs_filename = gr.Textbox(label="filename", max_lines=10) | |
| fs_file = gr.File(label="file") | |
| # fs_file_dir = gr.Textbox(value="data", label="file_dir") | |
| fs_file_dir = gr.Dropdown(choices=["data/dataset", "data/eval_data"], | |
| value="data/dataset", | |
| label="file_dir") | |
| fs_query = gr.Button("query", variant="primary") | |
| with gr.Column(scale=7): | |
| fs_filelist_dataset_state = gr.State(value=[]) | |
| fs_filelist_dataset = gr.Dataset( | |
| components=[fs_filename, fs_file], | |
| samples=fs_filelist_dataset_state.value, | |
| ) | |
| def when_click_query_files(file_dir: str = "data"): | |
| file_dir = project_path / file_dir | |
| dataset_state = list() | |
| for filename in file_dir.glob("**/*.*"): | |
| if filename.is_dir(): | |
| continue | |
| if filename.stem.startswith("."): | |
| continue | |
| if filename.name.endswith(".py"): | |
| continue | |
| if filename.name.endswith(".raw"): | |
| continue | |
| dataset_state.append(( | |
| filename.relative_to(file_dir).as_posix(), | |
| filename.as_posix(), | |
| )) | |
| dataset = gr.Dataset( | |
| components=[fs_filename, fs_file], | |
| samples=dataset_state, | |
| ) | |
| return dataset_state, dataset | |
| fs_filelist_dataset.click( | |
| fn=lambda x: ( | |
| x[1], x[1] | |
| ), | |
| inputs=[fs_filelist_dataset], | |
| outputs=[fs_filename, fs_file] | |
| ) | |
| fs_query.click( | |
| fn=when_click_query_files, | |
| inputs=[fs_file_dir], | |
| outputs=[fs_filelist_dataset_state, fs_filelist_dataset] | |
| ) | |
| return locals() | |
| if __name__ == "__main__": | |
| with gr.Blocks() as block: | |
| fs_components = get_fs_tab() | |
| block.launch() | |