Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch File upload/ Folder upload. Bulk Enhance #3540

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f1e9a5c
Batch File upload/ Folder upload. Bulk Enhance
ChrisColeTech Aug 18, 2024
ee4f442
remove unused imports
ChrisColeTech Aug 18, 2024
9f535e8
Change to resolve GitHub Advanced Security check
ChrisColeTech Aug 18, 2024
7a0b8ee
Rework Stop/Skip while bulk enhancing
ChrisColeTech Aug 18, 2024
2ab91c9
Update bulk_enhance_helpers.py
ChrisColeTech Aug 19, 2024
ec177f2
Update bulk_enhance_helpers.py
ChrisColeTech Aug 19, 2024
ad18a93
Update async_worker.py
ChrisColeTech Aug 20, 2024
e268cd5
Merge branch 'lllyasviel:main' into dev
ChrisColeTech Aug 20, 2024
83d0935
more code cleanup
ChrisColeTech Aug 20, 2024
3db125a
To resolve github CodeQL warning
ChrisColeTech Aug 20, 2024
4b90d70
Update async_worker.py
ChrisColeTech Aug 21, 2024
67edbf2
Update bulk_enhance_helpers.py
ChrisColeTech Aug 21, 2024
e68d7b5
automatic tkinter installation
ChrisColeTech Aug 22, 2024
1afc7b3
Update tkinter_installer.py
ChrisColeTech Aug 22, 2024
672baf0
Update launch.py
ChrisColeTech Aug 23, 2024
8921ac8
Remove code comments, added backend logic for perf monitor. renamed t…
ChrisColeTech Aug 24, 2024
7722d2c
html front end component for resource monitor
ChrisColeTech Aug 24, 2024
4848427
wired up perf monitor
ChrisColeTech Aug 24, 2024
85429b0
Update launch.py
ChrisColeTech Aug 24, 2024
4c32ebe
final touches on the perf monitor
ChrisColeTech Aug 26, 2024
5774787
perf monitor 2.0 with dragging
ChrisColeTech Aug 29, 2024
f0fa022
fix invisible element
ChrisColeTech Aug 30, 2024
c5a290a
remove unused code
ChrisColeTech Aug 30, 2024
c8d4d2d
Merge branch 'dev' of https://github.com/ChrisColeTech/Fooocus into dev
ChrisColeTech Aug 30, 2024
ce74b6b
speed up animation
ChrisColeTech Aug 30, 2024
eb934c9
Using websockets for resource monitor instead of rest api
ChrisColeTech Sep 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ user_path_config-deprecated.txt
/.coverage*
/auth.json
.DS_Store
/.venv
981 changes: 694 additions & 287 deletions modules/async_worker.py

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions modules/bulk_enhance_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import gradio as gr
import os
import modules.config
import modules.html
import modules.meta_parser

from tkinter import Tk, filedialog


def process_directories(directory_paths):
if not directory_paths:
return "No directories selected."

results = []
for directory in directory_paths:
# List files in the directory
files = os.listdir(directory)
results.append(f"Contents of {directory}:\n" + "\n".join(files))

return "\n\n".join(results)


def update_visibility(x):
# Add more updates for other components
return [gr.update(visible=x), gr.update(visible=x)]


def list_to_string(filenames):
# Join the filenames list into a comma-separated string
file_list = ', '.join(filenames)
return file_list


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()
file_list = list_to_string(filenames)
return file_list
else:
filename = "Files not seleceted"
root.destroy()
return None

elif data_type == "Folder":
filename = filedialog.askdirectory()
if filename:
if os.path.isdir(filename):
root.destroy()
return str(filename)
else:
root.destroy()
return str(filename)
else:
filename = "Folder not seleceted"
root.destroy()
return None


def on_file_change(files, data_type):
if files and data_type == "Files":
return gr.update(visible=True), gr.update(), gr.update(value=True)

# If no files are selected, hide file explorer and clear input_path
if not files and data_type == "Files":
return gr.update(visible=False), gr.update(value=""), gr.update(value=False)

if data_type == "Folder":
return gr.update(visible=False), gr.update(), gr.update(value=True)

return gr.update(visible=False), gr.update(), gr.update(value=False)


def on_input_change(input_path, file_explorer):
if input_path:
# Verify with normalised version of path
input_path = os.path.normpath(os.path.realpath(input_path))

if os.path.isdir(os.path.realpath(input_path)):
# Return an empty list if input_path is a directory

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression

This path depends on a [user-provided value](1).
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was resolved:
ChrisColeTech@b5e73ff

return None, gr.update(visible=True), gr.update(value=True)
else:
# Return an empty list if input_path is empty
return None, gr.update(visible=False), gr.update(value=False)

# Initialize a dictionary to track unique file names and their paths
unique_file_paths = {}

# Process the input_path string
if input_path:
# Clean up the input path string and split it into a list of file paths
file_paths_list = input_path.strip("()").replace("'", "").split(", ")
# Extract file names and ensure uniqueness
for path in file_paths_list:
file_name = os.path.basename(path)
unique_file_paths[file_name] = path

# Process file_explorer items if provided
if file_explorer:
# Extract 'orig_name' from each file_explorer object and ensure uniqueness
for item in file_explorer:
sanitized_path = item.orig_name
file_name = os.path.basename(sanitized_path)
# Store the path, replacing any existing path with the same file name
unique_file_paths[file_name] = sanitized_path

# Convert the dictionary values back to a list of unique file paths
if len(unique_file_paths.values()) > 0:
return list(unique_file_paths.values()), gr.update(visible=False), gr.update(value=True)
else:
return None, gr.update(visible=False), gr.update(value=False)


def on_click_clear():
return None, None, gr.update(visible=False), gr.update(visible=False)

# Function to set prompts based on the selected type


def update_prompts(selected_type):
# Ensure selected_type is a valid key and exists in the dictionary
if selected_type in modules.config.default_enhance_prompts:
positive_prompt = modules.config.default_enhance_prompts[selected_type]['positive']
negative_prompt = modules.config.default_enhance_prompts[selected_type]['negative']
return positive_prompt, negative_prompt
else:
# Returning default or empty values
return "Default positive prompt", "Default negative prompt"


def on_selection_change(selected_type):
# Get prompts based on selected_type
positive_prompt, negative_prompt = update_prompts(selected_type[0])

# Return the prompts
return positive_prompt, negative_prompt
Loading