|
""" |
|
current_file_path = Path(__file__).resolve() |
|
relative_path = "path/to/file" |
|
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve() |
|
|
|
|
|
def get_file_content(file): |
|
return (file,) |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`') |
|
submit_btn = gr.Button("Select") |
|
with gr.Row(): |
|
file = gr.FileExplorer( |
|
glob="**/components/*.py", |
|
# value=["themes/utils"], |
|
root_dir=absolute_path, |
|
ignore_glob="**/__init__.py", |
|
) |
|
|
|
file2 = gr.FileExplorer( |
|
glob="**/components/**/*.py", |
|
root_dir=absolute_path, |
|
ignore_glob="**/__init__.py", |
|
) |
|
submit_btn.click(lambda x: x, file, file2) |
|
|
|
gr.Markdown("---") |
|
gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`') |
|
with gr.Group(): |
|
with gr.Row(): |
|
file_3 = gr.FileExplorer( |
|
scale=1, |
|
glob="**/components/**/*.py", |
|
value=["themes/utils"], |
|
file_count="single", |
|
root_dir=absolute_path, |
|
ignore_glob="**/__init__.py", |
|
elem_id="file", |
|
) |
|
|
|
code = gr.Code(lines=30, scale=2, language="python") |
|
|
|
file_3.change(get_file_content, file_3, code) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
""" |
|
|
|
""" Version 1 |
|
def display_name_files(_folder_path): |
|
return f"{[img_name for img_name in os.listdir(_folder_path)]} \n" |
|
|
|
|
|
def on_browse(data_type): |
|
root = Tk() |
|
root.attributes("-topmost", True) |
|
root.withdraw() |
|
if data_type == "Files": |
|
filenames = filedialog.askopenfilenames() |
|
if len(filenames) > 0: |
|
root.destroy() |
|
return str(filenames) |
|
else: |
|
filename = "Files not seleceted" |
|
root.destroy() |
|
return str(filename) |
|
|
|
elif data_type == "Folder": |
|
filename = filedialog.askdirectory() |
|
print(filename) |
|
print(type(filename)) |
|
if filename: |
|
if os.path.isdir(filename): |
|
root.destroy() |
|
return str("\n".join(os.listdir(filename))) |
|
# return str(filename) |
|
else: |
|
root.destroy() |
|
return str(filename) |
|
else: |
|
filename = "Folder not seleceted" |
|
root.destroy() |
|
return str(filename) |
|
|
|
|
|
def main(): |
|
with gr.Blocks() as demo: |
|
data_type = gr.Radio( |
|
choices=["Files", "Folder"], value="Files", label="Offline data type" |
|
) |
|
input_path = gr.Textbox( |
|
label="Select Multiple videos", scale=5, interactive=False |
|
) |
|
image_browse_btn = gr.Button("Browse", min_width=1) |
|
image_browse_btn.click( |
|
on_browse, inputs=data_type, outputs=input_path, show_progress="hidden" |
|
) |
|
return demo |
|
|
|
|
|
demo = main() |
|
demo.launch(inbrowser=True) |
|
""" |
|
|
|
''' |
|
def get_image_name(_image): |
|
if _image.any(): |
|
# print(type(_image)) |
|
output_info = f""" |
|
Image shape: |
|
{_image.shape} |
|
""" |
|
return output_info |
|
else: |
|
return "No file uploaded" |
|
|
|
|
|
def list_images(dir): |
|
return [d.name for d in dir] |
|
|
|
|
|
with gr.Blocks() as interface: |
|
gr.Markdown("Import your image and then click the button to see the output.") |
|
with gr.Row(): |
|
input_img = gr.Image(label="Input Image", height=500, width=500) |
|
# output_img = gr.Image(label="Recognized Image") |
|
# display_df = gr.DataFrame(export_results) |
|
output_info = gr.Textbox() |
|
# export_info = gr.Textbox() |
|
labelling_btn = gr.Button("Apply Species Recognition") |
|
# export_btn = gr.Button("Export result as a CSV") |
|
labelling_btn.click(fn=get_image_name, inputs=input_img, outputs=[output_info]) |
|
# export_btn.click(fn=export_results, inputs=input_img, outputs=[export_info]) |
|
|
|
with gr.Row(): |
|
gr.Dataframe(pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})) |
|
|
|
# Launch the app |
|
if __name__ == "__main__": |
|
interface.launch() |
|
''' |
|
|