-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_webui_config.py
More file actions
109 lines (93 loc) · 3.85 KB
/
capture_webui_config.py
File metadata and controls
109 lines (93 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import requests
import json
import time
from datetime import datetime
# === CONFIG ===
url = "http://127.0.0.1:7860"
def get_current_options():
"""Get all current WebUI options"""
try:
response = requests.get(f"{url}/sdapi/v1/options")
response.raise_for_status()
options = response.json()
return options
except Exception as e:
print(f"Error getting options: {str(e)}")
return {}
def get_txt2img_default_params():
"""Get the default parameters for txt2img"""
try:
response = requests.get(f"{url}/sdapi/v1/txt2img")
response.raise_for_status()
return response.json()
except Exception as e:
print(f"Error getting txt2img params: {str(e)}")
return {}
def monitor_progress():
"""Monitor progress of current generation"""
try:
response = requests.get(f"{url}/sdapi/v1/progress")
response.raise_for_status()
progress = response.json()
return progress
except Exception as e:
print(f"Error getting progress: {str(e)}")
return {}
def save_config_to_file(config, filename):
"""Save configuration to a JSON file"""
try:
with open(filename, 'w') as f:
json.dump(config, f, indent=2)
print(f"✅ Saved to {filename}")
except Exception as e:
print(f"❌ Error saving to file: {str(e)}")
if __name__ == "__main__":
print("=== WebUI Configuration Capture Tool ===")
print("This tool captures the current WebUI configuration and default parameters.")
print("Use this after successfully generating an image with Flux in the WebUI.")
# Get timestamp for filenames
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
# Get and save current options
print("\nFetching current WebUI options...")
options = get_current_options()
if options:
# Extract important model info
model_info = {
"current_model": options.get("sd_model_checkpoint", "unknown"),
"current_vae": options.get("sd_vae", "unknown"),
}
# Check for Forge modules
if "forge_additional_modules" in options:
model_info["additional_modules"] = options["forge_additional_modules"]
print("\n=== Current Model Configuration ===")
print(json.dumps(model_info, indent=2))
# Save all options to file
options_file = f"webui_options_{timestamp}.json"
save_config_to_file(options, options_file)
# Get and save txt2img default parameters
print("\nFetching txt2img default parameters...")
txt2img_params = get_txt2img_default_params()
if txt2img_params:
# Save to file
params_file = f"txt2img_params_{timestamp}.json"
save_config_to_file(txt2img_params, params_file)
# Display key parameters
key_params = {k: txt2img_params.get(k) for k in [
"prompt", "negative_prompt", "steps", "sampler_name",
"sampler_index", "cfg_scale", "denoising_strength"
] if k in txt2img_params}
print("\n=== Current txt2img Parameters ===")
print(json.dumps(key_params, indent=2))
print("\n=== INSTRUCTIONS ===")
print("1. Generate a successful image with Flux in the WebUI interface")
print("2. Run this script immediately after to capture the working configuration")
print("3. Use the captured configuration in your API scripts")
print("4. Look for differences between your API payload and the WebUI defaults")
# Check if generation is in progress
print("\nChecking if generation is in progress...")
progress = monitor_progress()
if progress and progress.get("progress", 0) > 0:
print("Generation in progress. Progress info:")
print(json.dumps(progress, indent=2))
else:
print("No generation currently in progress")