Can you write a python script that: 1. lists all the files in a given directory, 2. puts…
- User
Can you write a python script that: 1. lists all the files in a given directory, 2. puts the filenames in a gradio dropdown, 3. returns the selected filename to a variable "selected"
Assistant
Here's a Python script that does that:
pythonimport gradio as gr import os def list_files(dir_path): files = os.listdir(dir_path) return files def get_selected(selected_file): selected = selected_file files = list_files("files/") # List files in the files/ directory # Create gradio app with dropdown of filenames app = gr.Interface(fn=get_selected, inputs="dropdown", outputs="text") app.inputs[0].options = files # Launch app and get selected filename app.launch(share=False) selected = app.outputs[0] print(selected) # Print selected filename
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.