Closed piovis2023 closed 2 months ago
Hi @piovis2023 apps running in a browser typically do not have access to a user's file system, so what you're describing cannot be achieved in Gradio directly. You have two options:
(1) Simply right click on the download file link and click "Save as...", which will open up the filesystem window
(2) Use gr.FileExplorer
to expose the developer's file system and let users select a destination. Note that this is going to expose the developer's file system, not the user's file system, but this is an option if you are developing a Gradio app only for local useage
Describe the bug
I just want to click save a button on the GUI. It should open windows explorer to the designated folder, where I can type and save the file. I've been working with ChatGPT, Claude 3.5 Sonnet and after 5 hours, still can't do this simple thing.
I do not want to a textbox in the GUI to create the filename, since it will create confusion. I want to create the file name via windows explorer.
My setup: Windows 11 OS Python 3.11 Conda env Latest Gradio version as of 06 Aug 2024.
Thanks you
Have you searched existing issues? π
Reproduction
Various attempts (only showing this requirement) [Try 1] import gradio as gr import os from pathlib import Path import subprocess import time
Configuration
category_config_folder = Path(os.path.join(os.getcwd(), "categoryconfig"))
Ensure the directory exists
category_config_folder.mkdir(parents=True, exist_ok=True)
Function to list all files in the category config folder
def list_files(): return [f.name for f in category_config_folder.glob("*.json")]
Function to open the category config folder
def open_folder(): path_to_open = os.path.realpath(category_config_folder) subprocess.Popen(f'explorer {path_to_open}')
Function to check for new files and update the dropdown
def refresh_dropdown(): time.sleep(5) # Wait for the user to create the file return list_files()
Interface elements
def create_interface(): with gr.Blocks() as demo: with gr.Row(): file_dropdown = gr.Dropdown(choices=list_files(), label="Category Files") open_folder_button = gr.Button("π") save_file_button = gr.Button("Refresh π")
Create and launch the interface
interface = create_interface() interface.launch()
[Try 2] import gradio as gr import os from pathlib import Path import subprocess import time
Configuration
category_config_folder = Path(os.path.join(os.getcwd(), "categoryconfig"))
Ensure the directory exists
category_config_folder.mkdir(parents=True, exist_ok=True)
Function to list all files in the category config folder
def list_files(): return [f.name for f in category_config_folder.glob("*.json")]
Function to open the category config folder
def open_folder(): path_to_open = os.path.realpath(category_config_folder) subprocess.Popen(f'explorer {path_to_open}')
Function to save a new file
def save_file(): path_to_open = os.path.realpath(category_config_folder) subprocess.Popen(f'explorer /select,{path_to_open}\newfile.json') time.sleep(5) # Wait for the user to save the file return gr.Dropdown.update(choices=list_files())
Interface elements
def create_interface(): with gr.Blocks() as demo: with gr.Row(): file_dropdown = gr.Dropdown(choices=list_files(), label="Category Files") open_folder_button = gr.Button("π") save_file_button = gr.Button("πΎ")
Create and launch the interface
interface = create_interface() interface.launch()
[Try 3] import gradio as gr import os from pathlib import Path import subprocess
Configuration
category_config_folder = Path(os.path.join(os.getcwd(), "categoryconfig"))
Ensure the directory exists
category_config_folder.mkdir(parents=True, exist_ok=True)
Function to list all files in the category config folder
def list_files(): return [f.name for f in category_config_folder.glob("*.json")]
Function to open the category config folder
def open_folder(): path_to_open = os.path.realpath(category_config_folder) subprocess.Popen(f'explorer {path_to_open}')
Function to save a new file and update the dropdown list
def save_file(): path_to_open = os.path.realpath(category_config_folder) subprocess.Popen(f'explorer /select,{path_to_open}\newfile.json') return gr.Dropdown.update(choices=list_files())
Interface elements
def create_interface(): with gr.Blocks() as demo: with gr.Row(): file_dropdown = gr.Dropdown(choices=list_files(), label="Category Files") open_folder_button = gr.Button("π") save_file_button = gr.Button("πΎ")
Create and launch the interface
interface = create_interface() interface.launch()
Screenshot
No response
Logs
No response
System Info
Severity
Blocking usage of gradio