Select directory path with gradio or tkinter

is it possible to select a directory path with gradio? I want to have a button when clicked I should be able to select directory, I tried with tkinter but that gives me error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!


import gradio as gr
import tkinter as tk
from tkinter import filedialog

def select_directory(selected_folder):
    root = tk.Tk()
    folder_path = filedialog.askdirectory()
    selected_folder.set_value(f"Selected Directory: {folder_path}")

with gr.Blocks(analytics_enabled=False) as ui_component:
    with gr.Row():
        selected_folder = gr.Textbox("", label="Selected Folder", lines=2)
        input_files = gr.Button("Select Directory"), selected_folder)