Skip to content

Commit 71deddc

Browse files
committed
RUFF formatting fixes
1 parent cde6798 commit 71deddc

5 files changed

Lines changed: 247 additions & 186 deletions

File tree

modules/interface.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ def update_stats(*args):
6464
queue_status_data = update_queue_status_with_thumbnails()
6565
jobs = job_queue.get_all_jobs()
6666
pending_count = sum(1 for j in jobs if str(j.status) == "JobStatus.PENDING")
67-
running_count = sum(1 for j in jobs if str(j.status) in ["JobStatus.RUNNING", "JobStatus.CANCELLING"])
67+
running_count = sum(
68+
1
69+
for j in jobs
70+
if str(j.status) in ["JobStatus.RUNNING", "JobStatus.CANCELLING"]
71+
)
6872
completed_count = sum(1 for j in jobs if str(j.status) == "JobStatus.COMPLETED")
6973
queue_stats_text = f"<p style='margin:0;color:white;' class='toolbar-text'>Queue: {pending_count} | Running: {running_count} | Completed: {completed_count}</p>"
7074
return queue_status_data, queue_stats_text

modules/ui/queue.py

Lines changed: 82 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,82 +6,86 @@
66
render_thumbnail_html,
77
get_queue_documentation,
88
render_queue_row,
9-
render_queue
9+
render_queue,
1010
)
1111

1212
logger = logging.getLogger(__name__)
1313

1414

1515
def format_queue_status(jobs):
1616
"""Format queue status with custom HTML templates."""
17-
17+
1818
rows = []
1919
for job in jobs:
2020
elapsed_time = ""
2121
if job.started_at:
2222
end_time = job.completed_at or time.time()
2323
elapsed_seconds = end_time - job.started_at
2424
elapsed_time = f"{elapsed_seconds:.2f}s"
25-
25+
2626
# Get job data
2727
generation_type = getattr(job, "generation_type", "Original")
2828
thumbnail = getattr(job, "thumbnail", None)
2929
thumbnail_html = render_thumbnail_html(thumbnail)
30-
30+
3131
# Get job settings from job.params (where JSON data is actually stored)
3232
width = job.params.get("resolutionW", 512) if hasattr(job, "params") else 512
3333
height = job.params.get("resolutionH", 512) if hasattr(job, "params") else 512
3434
size = f"{width}×{height}"
35-
35+
3636
# Get video length from total_second_length (already in seconds)
37-
total_seconds = job.params.get("total_second_length", 6) if hasattr(job, "params") else 6
37+
total_seconds = (
38+
job.params.get("total_second_length", 6) if hasattr(job, "params") else 6
39+
)
3840
length = f"{total_seconds}s" if total_seconds else "N/A"
39-
41+
4042
# Get seed from params
4143
seed = job.params.get("seed", "Random") if hasattr(job, "params") else "Random"
42-
44+
4345
# Get prompt from params
4446
prompt = job.params.get("prompt_text", "") if hasattr(job, "params") else ""
45-
47+
4648
# Get all job data for changed settings detection from job.params
4749
params = job.params if hasattr(job, "params") else {}
4850
job_data = {
49-
'prompt': prompt,
50-
'negative_prompt': params.get("n_prompt", ""),
51-
'seed': seed,
52-
'steps': params.get("steps", 25),
53-
'cfg': params.get("cfg", 1.0),
54-
'gs': params.get("gs", 10),
55-
'rs': params.get("rs", 0),
56-
'latent_type': params.get("latent_type", "Noise"),
57-
'latent_window_size': params.get("latent_window_size", 9),
58-
'resolutionW': params.get("resolutionW", 512),
59-
'resolutionH': params.get("resolutionH", 512),
60-
'model_type': params.get("model_type", generation_type),
61-
'generation_type': params.get("model_type", generation_type),
62-
'total_second_length': params.get("total_second_length", 6),
63-
'blend_sections': params.get("blend_sections", 4),
64-
'num_cleaned_frames': params.get("num_cleaned_frames", 0),
65-
'end_frame_strength': params.get("end_frame_strength", 1.0),
66-
'end_frame_image_path': params.get("end_frame_image_path", None),
67-
'end_frame_used': params.get("end_frame_used", "False"),
68-
'input_video': params.get("input_video", None),
69-
'video_path': params.get("video_path", None),
70-
'x_param': params.get("x_param", None),
71-
'y_param': params.get("y_param", None),
72-
'x_values': params.get("x_values", None),
73-
'y_values': params.get("y_values", None),
74-
'combine_with_source': params.get("combine_with_source", True),
75-
'use_teacache': params.get("use_teacache", False),
76-
'teacache_num_steps': params.get("teacache_num_steps", 25),
77-
'teacache_rel_l1_thresh': params.get("teacache_rel_l1_thresh", 0.15),
78-
'use_magcache': params.get("use_magcache", True),
79-
'magcache_threshold': params.get("magcache_threshold", 0.1),
80-
'magcache_max_consecutive_skips': params.get("magcache_max_consecutive_skips", 2),
81-
'magcache_retention_ratio': params.get("magcache_retention_ratio", 0.25),
82-
'loras': params.get("loras", {}),
51+
"prompt": prompt,
52+
"negative_prompt": params.get("n_prompt", ""),
53+
"seed": seed,
54+
"steps": params.get("steps", 25),
55+
"cfg": params.get("cfg", 1.0),
56+
"gs": params.get("gs", 10),
57+
"rs": params.get("rs", 0),
58+
"latent_type": params.get("latent_type", "Noise"),
59+
"latent_window_size": params.get("latent_window_size", 9),
60+
"resolutionW": params.get("resolutionW", 512),
61+
"resolutionH": params.get("resolutionH", 512),
62+
"model_type": params.get("model_type", generation_type),
63+
"generation_type": params.get("model_type", generation_type),
64+
"total_second_length": params.get("total_second_length", 6),
65+
"blend_sections": params.get("blend_sections", 4),
66+
"num_cleaned_frames": params.get("num_cleaned_frames", 0),
67+
"end_frame_strength": params.get("end_frame_strength", 1.0),
68+
"end_frame_image_path": params.get("end_frame_image_path", None),
69+
"end_frame_used": params.get("end_frame_used", "False"),
70+
"input_video": params.get("input_video", None),
71+
"video_path": params.get("video_path", None),
72+
"x_param": params.get("x_param", None),
73+
"y_param": params.get("y_param", None),
74+
"x_values": params.get("x_values", None),
75+
"y_values": params.get("y_values", None),
76+
"combine_with_source": params.get("combine_with_source", True),
77+
"use_teacache": params.get("use_teacache", False),
78+
"teacache_num_steps": params.get("teacache_num_steps", 25),
79+
"teacache_rel_l1_thresh": params.get("teacache_rel_l1_thresh", 0.15),
80+
"use_magcache": params.get("use_magcache", True),
81+
"magcache_threshold": params.get("magcache_threshold", 0.1),
82+
"magcache_max_consecutive_skips": params.get(
83+
"magcache_max_consecutive_skips", 2
84+
),
85+
"magcache_retention_ratio": params.get("magcache_retention_ratio", 0.25),
86+
"loras": params.get("loras", {}),
8387
}
84-
88+
8589
# Render each row using the template
8690
row_html = render_queue_row(
8791
job_id=job.id[:6] + "...",
@@ -92,14 +96,18 @@ def format_queue_status(jobs):
9296
size=size,
9397
length=length,
9498
seed=str(seed),
95-
started=time.strftime("%H:%M:%S", time.localtime(job.started_at)) if job.started_at else "--",
96-
completed=time.strftime("%H:%M:%S", time.localtime(job.completed_at)) if job.completed_at else "--",
99+
started=time.strftime("%H:%M:%S", time.localtime(job.started_at))
100+
if job.started_at
101+
else "--",
102+
completed=time.strftime("%H:%M:%S", time.localtime(job.completed_at))
103+
if job.completed_at
104+
else "--",
97105
elapsed=elapsed_time or "--",
98106
thumbnail=thumbnail_html,
99-
job_data=job_data
107+
job_data=job_data,
100108
)
101109
rows.append(row_html)
102-
110+
103111
# Render the complete queue
104112
return render_queue(rows)
105113

@@ -114,29 +122,46 @@ def update_queue_status_with_thumbnails():
114122
job.queue_position = job_queue.get_queue_position(job.id)
115123
if job_queue.current_job:
116124
# Only set to RUNNING if not already in a cancellation state
117-
if job_queue.current_job.status not in [JobStatus.CANCELLING, JobStatus.CANCELLED]:
125+
if job_queue.current_job.status not in [
126+
JobStatus.CANCELLING,
127+
JobStatus.CANCELLED,
128+
]:
118129
job_queue.current_job.status = JobStatus.RUNNING
119-
130+
120131
# Sort jobs according to the requested priority:
121132
# 1. Running and Cancelling items first (same job transitioning states)
122133
# 2. Queued (pending) items in ascending order by created_at
123134
# 3. Editing items (future feature)
124135
# 4. Completed, Failed, and Cancelled items in descending order by completed_at
125136
def sort_key(job):
126137
if job.status in [JobStatus.RUNNING, JobStatus.CANCELLING]:
127-
return (0, job.created_at) # Running/Cancelling items first (same priority - never coexist)
138+
return (
139+
0,
140+
job.created_at,
141+
) # Running/Cancelling items first (same priority - never coexist)
128142
elif job.status == JobStatus.PENDING:
129143
# Sort by order number if available, otherwise fall back to created_at
130-
return (1, job.order_number if job.order_number is not None else job.created_at)
144+
return (
145+
1,
146+
job.order_number
147+
if job.order_number is not None
148+
else job.created_at,
149+
)
131150
elif job.status == JobStatus.EDITING:
132-
return (2, job.created_at) # Editing items third, ordered by creation time
151+
return (
152+
2,
153+
job.created_at,
154+
) # Editing items third, ordered by creation time
133155
else: # COMPLETED, FAILED, CANCELLED
134156
# Use completed_at if available, otherwise use created_at, with descending order
135157
timestamp = job.completed_at if job.completed_at else job.created_at
136-
return (3, -timestamp) # Completed/Failed/Cancelled items last, descending order
137-
158+
return (
159+
3,
160+
-timestamp,
161+
) # Completed/Failed/Cancelled items last, descending order
162+
138163
jobs.sort(key=sort_key)
139-
164+
140165
return format_queue_status(jobs)
141166
except ImportError:
142167
logging.error(
@@ -175,7 +200,7 @@ def create_queue_ui():
175200
# Create custom queue HTML component
176201
queue_status = gr.HTML(
177202
render_queue([]), # Start with empty queue
178-
label="Job Queue"
203+
label="Job Queue",
179204
)
180205
with gr.Accordion("Queue Documentation", open=False):
181206
gr.Markdown(get_queue_documentation())

0 commit comments

Comments
 (0)