diff --git a/src/streamlit_app.py b/src/streamlit_app.py index caa6e83..598d24f 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -19,6 +19,14 @@ from main import ( setup_logging ) +def is_running_locally(): + """Check if the app is running locally or in cloud environment""" + try: + import tkinter + return True + except ImportError: + return False + # Configure page st.set_page_config( page_title="Office Protection Remover", @@ -166,19 +174,20 @@ with col1: key='source_dir_input', help="Enter the full path to the directory containing files to process") - if st.button("Browse Source Directory", key='source_browse'): - try: - root = tk.Tk() - root.withdraw() - root.wm_attributes('-topmost', 1) - path = filedialog.askdirectory(title="Select Source Directory") - root.destroy() - if path: - st.session_state['source_dir'] = path - st.session_state['source_dir_input'] = path - st.experimental_rerun() - except Exception as e: - st.error(f"Error opening directory dialog: {str(e)}") + if is_running_locally(): + if st.button("Browse Source Directory", key='source_browse'): + try: + root = tk.Tk() + root.withdraw() + root.wm_attributes('-topmost', 1) + path = filedialog.askdirectory(title="Select Source Directory") + root.destroy() + if path: + st.session_state['source_dir'] = path + st.session_state['source_dir_input'] = path + st.experimental_rerun() + except Exception as e: + st.error(f"Error opening directory dialog: {str(e)}") # Destination Directory dest_dir = st.text_input("Destination Directory Path", @@ -186,19 +195,20 @@ with col1: key='dest_dir_input', help="Enter the full path where processed files will be saved") - if st.button("Browse Destination Directory", key='dest_browse'): - try: - root = tk.Tk() - root.withdraw() - root.wm_attributes('-topmost', 1) - path = filedialog.askdirectory(title="Select Destination Directory") - root.destroy() - if path: - st.session_state['dest_dir'] = path - st.session_state['dest_dir_input'] = path - st.experimental_rerun() - except Exception as e: - st.error(f"Error opening directory dialog: {str(e)}") + if is_running_locally(): + if st.button("Browse Destination Directory", key='dest_browse'): + try: + root = tk.Tk() + root.withdraw() + root.wm_attributes('-topmost', 1) + path = filedialog.askdirectory(title="Select Destination Directory") + root.destroy() + if path: + st.session_state['dest_dir'] = path + st.session_state['dest_dir_input'] = path + st.experimental_rerun() + except Exception as e: + st.error(f"Error opening directory dialog: {str(e)}") with col2: if file_type == "Excel": @@ -223,12 +233,20 @@ with col2: password_path = st.text_input("Password File Path", help="Enter the full path to the text file containing passwords", value=st.session_state.get('password_path', '')) - password_browse = st.button("Browse Password File") - if password_browse: - path = get_file_path("Select Password File", [("Text Files", "*.txt")]) - if path: - st.session_state['password_path'] = path - st.experimental_rerun() + if is_running_locally(): + if st.button("Browse Password File"): + try: + root = tk.Tk() + root.withdraw() + root.wm_attributes('-topmost', 1) + path = filedialog.askopenfilename(title="Select Password File", + filetypes=[("Text Files", "*.txt")]) + root.destroy() + if path: + st.session_state['password_path'] = path + st.experimental_rerun() + except Exception as e: + st.error(f"Error opening file dialog: {str(e)}") if password_path and os.path.exists(password_path): with open(password_path, 'r', encoding='utf-8') as pf: