00Boobs00 commited on
Commit
82229f9
·
verified ·
1 Parent(s): 6757240

Upscale this by automatically adding the trigger word/phrase to the prompt and refactoring it with in-depth optimization specific to the base models and LORA models we are using here.

Browse files
Files changed (3) hide show
  1. components/lora-selector.js +32 -8
  2. index.html +1 -1
  3. script.js +58 -2
components/lora-selector.js CHANGED
@@ -93,16 +93,18 @@ class LoraSelector extends HTMLElement {
93
 
94
  // Clear loading option
95
  selectElement.innerHTML = '<option value="">Select a LoRA model</option>';
96
-
97
  // Add each LoRA model as an option
98
  safetensorsFiles.forEach(file => {
99
  const option = document.createElement('option');
100
- option.value = file.rfilename;
101
- option.textContent = file.rfilename.replace('.safetensors', '');
 
 
 
 
102
  selectElement.appendChild(option);
103
  });
104
-
105
- // Dispatch event when models are loaded
106
  this.dispatchEvent(new CustomEvent('loras-loaded', {
107
  detail: { models: safetensorsFiles },
108
  bubbles: true
@@ -118,13 +120,35 @@ class LoraSelector extends HTMLElement {
118
  }
119
  }
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  get selectedValue() {
122
- return this.shadowRoot.getElementById('loraSelect').value;
 
 
 
 
 
123
  }
124
 
125
  set selectedValue(value) {
126
- this.shadowRoot.getElementById('loraSelect').value = value;
127
  }
128
  }
129
 
130
- customElements.define('lora-selector', LoraSelector);
 
93
 
94
  // Clear loading option
95
  selectElement.innerHTML = '<option value="">Select a LoRA model</option>';
 
96
  // Add each LoRA model as an option
97
  safetensorsFiles.forEach(file => {
98
  const option = document.createElement('option');
99
+ const modelName = file.rfilename.replace('.safetensors', '');
100
+ option.value = JSON.stringify({
101
+ filename: file.rfilename,
102
+ trigger: this.getTriggerWord(modelName)
103
+ });
104
+ option.textContent = modelName;
105
  selectElement.appendChild(option);
106
  });
107
+ // Dispatch event when models are loaded
 
108
  this.dispatchEvent(new CustomEvent('loras-loaded', {
109
  detail: { models: safetensorsFiles },
110
  bubbles: true
 
120
  }
121
  }
122
 
123
+ getTriggerWord(modelName) {
124
+ const triggers = {
125
+ 'Wan2.2-Disco-Diffusion': 'disco style',
126
+ 'Wan2.2-Futuristic-City': 'futuristic cityscape',
127
+ 'Wan2.2-Anime-Art': 'anime art style',
128
+ 'Wan2.2-Cyberpunk': 'cyberpunk aesthetic',
129
+ 'Wan2.2-Fantasy': 'fantasy illustration',
130
+ 'Wan2.2-Photorealistic': 'photorealistic',
131
+ 'Wan2.2-Watercolor': 'watercolor painting',
132
+ 'Wan2.2-Oil-Painting': 'oil painting',
133
+ 'Wan2.2-Sketch': 'pencil sketch',
134
+ 'Wan2.2-Impressionist': 'impressionist painting'
135
+ };
136
+
137
+ return triggers[modelName] || 'enhanced style';
138
+ }
139
+
140
  get selectedValue() {
141
+ const selected = this.shadowRoot.getElementById('loraSelect').value;
142
+ try {
143
+ return JSON.parse(selected);
144
+ } catch {
145
+ return { filename: '', trigger: '' };
146
+ }
147
  }
148
 
149
  set selectedValue(value) {
150
+ this.shadowRoot.getElementById('loraSelect').value = JSON.stringify(value);
151
  }
152
  }
153
 
154
+ customElements.define('lora-selector', LoraSelector);
index.html CHANGED
@@ -1,5 +1,5 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
1
  <!DOCTYPE html>
2
+ <html lang="en">upsca
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
script.js CHANGED
@@ -44,7 +44,6 @@ document.addEventListener('DOMContentLoaded', function() {
44
  });
45
  // Handle LoRA selection
46
  const loraSelector = document.getElementById('loraSelector');
47
-
48
  // Generate button interaction
49
  const generateBtn = document.querySelector('button.bg-gradient-to-r');
50
  generateBtn.addEventListener('click', function() {
@@ -65,6 +64,13 @@ document.addEventListener('DOMContentLoaded', function() {
65
  const selectedLora = loraSelector.selectedValue;
66
  console.log('Selected LoRA:', selectedLora);
67
 
 
 
 
 
 
 
 
68
  // Simulate processing time
69
  setTimeout(() => {
70
  // Reset button
@@ -81,4 +87,54 @@ document.addEventListener('DOMContentLoaded', function() {
81
  `;
82
  }, 3000);
83
  });
84
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  });
45
  // Handle LoRA selection
46
  const loraSelector = document.getElementById('loraSelector');
 
47
  // Generate button interaction
48
  const generateBtn = document.querySelector('button.bg-gradient-to-r');
49
  generateBtn.addEventListener('click', function() {
 
64
  const selectedLora = loraSelector.selectedValue;
65
  console.log('Selected LoRA:', selectedLora);
66
 
67
+ // Optimize prompt based on selected LoRA
68
+ const promptTextarea = document.querySelector('textarea:not([placeholder])');
69
+ const originalPrompt = promptTextarea.value;
70
+ const optimizedPrompt = optimizePromptForLora(originalPrompt, selectedLora.trigger);
71
+ promptTextarea.value = optimizedPrompt;
72
+ console.log('Optimized prompt:', optimizedPrompt);
73
+
74
  // Simulate processing time
75
  setTimeout(() => {
76
  // Reset button
 
87
  `;
88
  }, 3000);
89
  });
90
+ });
91
+
92
+ function optimizePromptForLora(basePrompt, loraTrigger) {
93
+ if (!loraTrigger) return basePrompt;
94
+
95
+ // Base model optimizations
96
+ const baseOptimizations = [
97
+ "high quality, detailed, sharp focus",
98
+ "professional lighting, cinematic composition",
99
+ "8k resolution, ultra detailed",
100
+ "masterpiece, best quality"
101
+ ];
102
+
103
+ // Motion-specific enhancements
104
+ const motionEnhancements = [
105
+ "smooth camera motion",
106
+ "dynamic movement",
107
+ "fluid animation",
108
+ "cinematic pan"
109
+ ];
110
+
111
+ // Combine all elements
112
+ const allElements = [...baseOptimizations, ...motionEnhancements];
113
+
114
+ // Check if base prompt already contains optimization keywords
115
+ const hasQualityKeywords = baseOptimizations.some(keyword =>
116
+ basePrompt.toLowerCase().includes(keyword.split(',')[0].toLowerCase())
117
+ );
118
+
119
+ const hasMotionKeywords = motionEnhancements.some(keyword =>
120
+ basePrompt.toLowerCase().includes(keyword.split(',')[0].toLowerCase())
121
+ );
122
+
123
+ // Add missing optimizations
124
+ let optimizedPrompt = basePrompt;
125
+
126
+ if (!hasQualityKeywords) {
127
+ optimizedPrompt = `${allElements.slice(0, 2).join(', ')}, ${optimizedPrompt}`;
128
+ }
129
+
130
+ if (!hasMotionKeywords) {
131
+ optimizedPrompt = `${optimizedPrompt}, ${motionEnhancements.slice(0, 2).join(', ')}`;
132
+ }
133
+
134
+ // Add LoRA trigger word
135
+ if (loraTrigger && !basePrompt.toLowerCase().includes(loraTrigger.toLowerCase())) {
136
+ optimizedPrompt = `${optimizedPrompt}, ${loraTrigger}`;
137
+ }
138
+
139
+ return optimizedPrompt;
140
+ }