Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -25,251 +25,6 @@ TITLE = """
|
|
| 25 |
<p><em>Powered by Dolphin 2.6 Mistral 7B DPO - Venice Edition Uncensored</em></p>
|
| 26 |
</div>
|
| 27 |
<hr>
|
| 28 |
-
|
| 29 |
-
<script>
|
| 30 |
-
// Venice Edition Import Functionality
|
| 31 |
-
function fillVeniceEditionFields(data) {
|
| 32 |
-
console.log('π― Filling Venice Edition fields with data:', data);
|
| 33 |
-
|
| 34 |
-
if (!data || !data.data) {
|
| 35 |
-
console.error('β Invalid data format');
|
| 36 |
-
return false;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
const joyCaptionData = data.data;
|
| 40 |
-
let fieldsFound = 0;
|
| 41 |
-
let fieldsFilled = 0;
|
| 42 |
-
|
| 43 |
-
// Find all textareas and inputs in Venice Edition
|
| 44 |
-
const textFields = document.querySelectorAll('textarea, input[type="text"]');
|
| 45 |
-
fieldsFound = textFields.length;
|
| 46 |
-
|
| 47 |
-
console.log(`π Found ${fieldsFound} text fields in Venice Edition`);
|
| 48 |
-
|
| 49 |
-
// Function to fill a field by matching placeholder or context
|
| 50 |
-
function fillFieldByContext(searchTerms, value, fieldType = 'general') {
|
| 51 |
-
for (const field of textFields) {
|
| 52 |
-
const placeholder = (field.placeholder || '').toLowerCase();
|
| 53 |
-
const label = getFieldLabel(field).toLowerCase();
|
| 54 |
-
const context = (placeholder + ' ' + label).toLowerCase();
|
| 55 |
-
|
| 56 |
-
// Check if any search term matches
|
| 57 |
-
const matches = searchTerms.some(term => context.includes(term.toLowerCase()));
|
| 58 |
-
|
| 59 |
-
if (matches && !field.value.trim()) { // Only fill if empty
|
| 60 |
-
field.value = value;
|
| 61 |
-
field.dispatchEvent(new Event('input', { bubbles: true }));
|
| 62 |
-
field.dispatchEvent(new Event('change', { bubbles: true }));
|
| 63 |
-
fieldsFilled++;
|
| 64 |
-
console.log(`β
Filled ${fieldType}: ${value.substring(0, 50)}...`);
|
| 65 |
-
return true;
|
| 66 |
-
}
|
| 67 |
-
}
|
| 68 |
-
return false;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
// Fill fields based on JoyCaption data
|
| 72 |
-
if (joyCaptionData.caption_engaging) {
|
| 73 |
-
fillFieldByContext(['original', 'description', 'paste your image'], joyCaptionData.caption_engaging, 'Engaging Caption');
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
if (joyCaptionData.caption_casual_friend && !fieldsFilled) {
|
| 77 |
-
fillFieldByContext(['original', 'description', 'paste your image'], joyCaptionData.caption_casual_friend, 'Casual Caption');
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
if (joyCaptionData.caption_keywords && !fieldsFilled) {
|
| 81 |
-
fillFieldByContext(['original', 'description', 'paste your image'], joyCaptionData.caption_keywords, 'Keywords Caption');
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
if (joyCaptionData.keywords) {
|
| 85 |
-
fillFieldByContext(['keyword', 'seo', 'required'], joyCaptionData.keywords, 'Keywords');
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
if (joyCaptionData.custom_instructions) {
|
| 89 |
-
fillFieldByContext(['correction', 'manual', 'guidance'], joyCaptionData.custom_instructions, 'Custom Instructions');
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
// If no specific matches, fill the first few large text areas with captions
|
| 93 |
-
if (fieldsFilled === 0 && (joyCaptionData.caption_engaging || joyCaptionData.caption_casual_friend || joyCaptionData.caption_keywords)) {
|
| 94 |
-
const largeTextareas = Array.from(textFields).filter(field =>
|
| 95 |
-
field.tagName === 'TEXTAREA' && !field.value.trim()
|
| 96 |
-
);
|
| 97 |
-
|
| 98 |
-
let index = 0;
|
| 99 |
-
const captions = [joyCaptionData.caption_engaging, joyCaptionData.caption_casual_friend, joyCaptionData.caption_keywords].filter(Boolean);
|
| 100 |
-
|
| 101 |
-
if (captions.length > 0 && largeTextareas[index]) {
|
| 102 |
-
largeTextareas[index].value = captions[0];
|
| 103 |
-
largeTextareas[index].dispatchEvent(new Event('input', { bubbles: true }));
|
| 104 |
-
fieldsFilled++;
|
| 105 |
-
console.log(`β
Filled textarea ${index} with caption`);
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
console.log(`π Filled ${fieldsFilled} out of ${fieldsFound} fields`);
|
| 110 |
-
return fieldsFilled > 0;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
function getFieldLabel(field) {
|
| 114 |
-
// Try to find associated label
|
| 115 |
-
if (field.id) {
|
| 116 |
-
const label = document.querySelector(`label[for="${field.id}"]`);
|
| 117 |
-
if (label) return label.textContent || '';
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
// Look in parent elements for text context
|
| 121 |
-
let parent = field.parentElement;
|
| 122 |
-
let levels = 0;
|
| 123 |
-
while (parent && levels < 3) {
|
| 124 |
-
const labels = parent.querySelectorAll('label, span, div');
|
| 125 |
-
for (const label of labels) {
|
| 126 |
-
const text = label.textContent || '';
|
| 127 |
-
if (text.length > 0 && text.length < 100) {
|
| 128 |
-
return text;
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
parent = parent.parentElement;
|
| 132 |
-
levels++;
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
return field.placeholder || '';
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
function loadFromFile(event) {
|
| 139 |
-
const file = event.target.files[0];
|
| 140 |
-
if (!file) return;
|
| 141 |
-
|
| 142 |
-
const reader = new FileReader();
|
| 143 |
-
reader.onload = function(e) {
|
| 144 |
-
try {
|
| 145 |
-
const data = JSON.parse(e.target.result);
|
| 146 |
-
const success = fillVeniceEditionFields(data);
|
| 147 |
-
|
| 148 |
-
if (success) {
|
| 149 |
-
alert(`β
Successfully imported and filled Venice Edition fields!`);
|
| 150 |
-
} else {
|
| 151 |
-
alert('β οΈ Data imported but no matching fields found. Check field labels.');
|
| 152 |
-
}
|
| 153 |
-
} catch (error) {
|
| 154 |
-
console.error('β Import error:', error);
|
| 155 |
-
alert('β Failed to import file: ' + error.message);
|
| 156 |
-
}
|
| 157 |
-
};
|
| 158 |
-
reader.readAsText(file);
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
function loadFromClipboard() {
|
| 162 |
-
navigator.clipboard.readText().then(text => {
|
| 163 |
-
try {
|
| 164 |
-
const data = JSON.parse(text);
|
| 165 |
-
const success = fillVeniceEditionFields(data);
|
| 166 |
-
|
| 167 |
-
if (success) {
|
| 168 |
-
alert(`β
Successfully imported from clipboard and filled Venice Edition fields!`);
|
| 169 |
-
} else {
|
| 170 |
-
alert('β οΈ Data imported but no matching fields found. Check field labels.');
|
| 171 |
-
}
|
| 172 |
-
} catch (error) {
|
| 173 |
-
console.error('β Clipboard import error:', error);
|
| 174 |
-
alert('β Failed to import from clipboard: Invalid JSON format');
|
| 175 |
-
}
|
| 176 |
-
}).catch(err => {
|
| 177 |
-
console.error('β Clipboard read error:', err);
|
| 178 |
-
alert('β Failed to read clipboard: ' + err.message);
|
| 179 |
-
});
|
| 180 |
-
}
|
| 181 |
-
|
| 182 |
-
function createImportButtons() {
|
| 183 |
-
// Remove existing buttons first
|
| 184 |
-
const existingContainer = document.getElementById('venice-import-container');
|
| 185 |
-
if (existingContainer) existingContainer.remove();
|
| 186 |
-
|
| 187 |
-
// Create import button container
|
| 188 |
-
const container = document.createElement('div');
|
| 189 |
-
container.id = 'venice-import-container';
|
| 190 |
-
container.style.cssText = `
|
| 191 |
-
position: fixed;
|
| 192 |
-
top: 20px;
|
| 193 |
-
right: 20px;
|
| 194 |
-
z-index: 9999;
|
| 195 |
-
display: flex;
|
| 196 |
-
flex-direction: column;
|
| 197 |
-
gap: 10px;
|
| 198 |
-
`;
|
| 199 |
-
|
| 200 |
-
// Create file input (hidden)
|
| 201 |
-
const fileInput = document.createElement('input');
|
| 202 |
-
fileInput.type = 'file';
|
| 203 |
-
fileInput.accept = '.json';
|
| 204 |
-
fileInput.style.display = 'none';
|
| 205 |
-
fileInput.addEventListener('change', loadFromFile);
|
| 206 |
-
|
| 207 |
-
// Create import from file button
|
| 208 |
-
const importFileBtn = document.createElement('button');
|
| 209 |
-
importFileBtn.innerHTML = 'π Import from File';
|
| 210 |
-
importFileBtn.style.cssText = `
|
| 211 |
-
background: linear-gradient(135deg, #2e7d32, #388e3c);
|
| 212 |
-
color: white;
|
| 213 |
-
border: none;
|
| 214 |
-
padding: 12px 20px;
|
| 215 |
-
border-radius: 25px;
|
| 216 |
-
font-weight: 600;
|
| 217 |
-
cursor: pointer;
|
| 218 |
-
box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
|
| 219 |
-
transition: all 0.3s ease;
|
| 220 |
-
`;
|
| 221 |
-
|
| 222 |
-
importFileBtn.addEventListener('mouseover', () => {
|
| 223 |
-
importFileBtn.style.transform = 'translateY(-2px)';
|
| 224 |
-
importFileBtn.style.boxShadow = '0 6px 16px rgba(46, 125, 50, 0.4)';
|
| 225 |
-
});
|
| 226 |
-
|
| 227 |
-
importFileBtn.addEventListener('mouseout', () => {
|
| 228 |
-
importFileBtn.style.transform = 'translateY(0)';
|
| 229 |
-
importFileBtn.style.boxShadow = '0 4px 12px rgba(46, 125, 50, 0.3)';
|
| 230 |
-
});
|
| 231 |
-
|
| 232 |
-
importFileBtn.addEventListener('click', () => fileInput.click());
|
| 233 |
-
|
| 234 |
-
// Create import from clipboard button
|
| 235 |
-
const importClipBtn = document.createElement('button');
|
| 236 |
-
importClipBtn.innerHTML = 'π Import from Clipboard';
|
| 237 |
-
importClipBtn.style.cssText = `
|
| 238 |
-
background: linear-gradient(135deg, #1976d2, #1565c0);
|
| 239 |
-
color: white;
|
| 240 |
-
border: none;
|
| 241 |
-
padding: 12px 20px;
|
| 242 |
-
border-radius: 25px;
|
| 243 |
-
font-weight: 600;
|
| 244 |
-
cursor: pointer;
|
| 245 |
-
box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
|
| 246 |
-
transition: all 0.3s ease;
|
| 247 |
-
`;
|
| 248 |
-
|
| 249 |
-
importClipBtn.addEventListener('mouseover', () => {
|
| 250 |
-
importClipBtn.style.transform = 'translateY(-2px)';
|
| 251 |
-
importClipBtn.style.boxShadow = '0 6px 16px rgba(25, 118, 210, 0.4)';
|
| 252 |
-
});
|
| 253 |
-
|
| 254 |
-
importClipBtn.addEventListener('mouseout', () => {
|
| 255 |
-
importClipBtn.style.transform = 'translateY(0)';
|
| 256 |
-
importClipBtn.style.boxShadow = '0 4px 12px rgba(25, 118, 210, 0.3)';
|
| 257 |
-
});
|
| 258 |
-
|
| 259 |
-
importClipBtn.addEventListener('click', loadFromClipboard);
|
| 260 |
-
|
| 261 |
-
// Add elements to container
|
| 262 |
-
container.appendChild(fileInput);
|
| 263 |
-
container.appendChild(importFileBtn);
|
| 264 |
-
container.appendChild(importClipBtn);
|
| 265 |
-
|
| 266 |
-
document.body.appendChild(container);
|
| 267 |
-
console.log('β
Import buttons created');
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
// Auto-create buttons when page loads
|
| 271 |
-
setTimeout(createImportButtons, 3000); // Wait for Gradio to load
|
| 272 |
-
</script>
|
| 273 |
"""
|
| 274 |
|
| 275 |
print("π Loading Venice Edition NSFW Enhancer... v2.1")
|
|
@@ -753,8 +508,266 @@ def enhance_text(original_text, seo_keywords="", style="Professional", male_supp
|
|
| 753 |
error_time = time.time() - start_time
|
| 754 |
return f"β Error after {error_time:.1f}s: {str(e)[:300]}..."
|
| 755 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 756 |
# Gradio Interface - TWO COLUMNS ONLY
|
| 757 |
-
with gr.Blocks(title="Venice Edition NSFW Enhancer", theme=gr.themes.Soft()) as demo:
|
| 758 |
gr.HTML(TITLE)
|
| 759 |
|
| 760 |
with gr.Row():
|
|
|
|
| 25 |
<p><em>Powered by Dolphin 2.6 Mistral 7B DPO - Venice Edition Uncensored</em></p>
|
| 26 |
</div>
|
| 27 |
<hr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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: {str(e)[:300]}..."
|
| 510 |
|
| 511 |
+
# JavaScript for import functionality
|
| 512 |
+
IMPORT_JS = """
|
| 513 |
+
<script>
|
| 514 |
+
// Venice Edition Import Functionality
|
| 515 |
+
function fillVeniceEditionFields(data) {
|
| 516 |
+
console.log('π― Filling Venice Edition fields with data:', data);
|
| 517 |
+
|
| 518 |
+
if (!data || !data.data) {
|
| 519 |
+
console.error('β Invalid data format');
|
| 520 |
+
return false;
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
const joyCaptionData = data.data;
|
| 524 |
+
let fieldsFound = 0;
|
| 525 |
+
let fieldsFilled = 0;
|
| 526 |
+
|
| 527 |
+
// Find all textareas and inputs in Venice Edition
|
| 528 |
+
const textFields = document.querySelectorAll('textarea, input[type="text"]');
|
| 529 |
+
fieldsFound = textFields.length;
|
| 530 |
+
|
| 531 |
+
console.log(`π Found ${fieldsFound} text fields in Venice Edition`);
|
| 532 |
+
|
| 533 |
+
// Function to fill a field by matching placeholder or context
|
| 534 |
+
function fillFieldByContext(searchTerms, value, fieldType = 'general') {
|
| 535 |
+
for (const field of textFields) {
|
| 536 |
+
const placeholder = (field.placeholder || '').toLowerCase();
|
| 537 |
+
const label = getFieldLabel(field).toLowerCase();
|
| 538 |
+
const context = (placeholder + ' ' + label).toLowerCase();
|
| 539 |
+
|
| 540 |
+
// Check if any search term matches
|
| 541 |
+
const matches = searchTerms.some(term => context.includes(term.toLowerCase()));
|
| 542 |
+
|
| 543 |
+
if (matches && !field.value.trim()) { // Only fill if empty
|
| 544 |
+
field.value = value;
|
| 545 |
+
field.dispatchEvent(new Event('input', { bubbles: true }));
|
| 546 |
+
field.dispatchEvent(new Event('change', { bubbles: true }));
|
| 547 |
+
fieldsFilled++;
|
| 548 |
+
console.log(`β
Filled ${fieldType}: ${value.substring(0, 50)}...`);
|
| 549 |
+
return true;
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
return false;
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
// Fill fields based on JoyCaption data
|
| 556 |
+
if (joyCaptionData.caption_engaging) {
|
| 557 |
+
fillFieldByContext(['original', 'description', 'paste your image'], joyCaptionData.caption_engaging, 'Engaging Caption');
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
if (joyCaptionData.caption_casual_friend && !fieldsFilled) {
|
| 561 |
+
fillFieldByContext(['original', 'description', 'paste your image'], joyCaptionData.caption_casual_friend, 'Casual Caption');
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
if (joyCaptionData.caption_keywords && !fieldsFilled) {
|
| 565 |
+
fillFieldByContext(['original', 'description', 'paste your image'], joyCaptionData.caption_keywords, 'Keywords Caption');
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
if (joyCaptionData.keywords) {
|
| 569 |
+
fillFieldByContext(['keyword', 'seo', 'required'], joyCaptionData.keywords, 'Keywords');
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
if (joyCaptionData.custom_instructions) {
|
| 573 |
+
fillFieldByContext(['correction', 'manual', 'guidance'], joyCaptionData.custom_instructions, 'Custom Instructions');
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
// If no specific matches, fill the first few large text areas with captions
|
| 577 |
+
if (fieldsFilled === 0 && (joyCaptionData.caption_engaging || joyCaptionData.caption_casual_friend || joyCaptionData.caption_keywords)) {
|
| 578 |
+
const largeTextareas = Array.from(textFields).filter(field =>
|
| 579 |
+
field.tagName === 'TEXTAREA' && !field.value.trim()
|
| 580 |
+
);
|
| 581 |
+
|
| 582 |
+
let index = 0;
|
| 583 |
+
const captions = [joyCaptionData.caption_engaging, joyCaptionData.caption_casual_friend, joyCaptionData.caption_keywords].filter(Boolean);
|
| 584 |
+
|
| 585 |
+
if (captions.length > 0 && largeTextareas[index]) {
|
| 586 |
+
largeTextareas[index].value = captions[0];
|
| 587 |
+
largeTextareas[index].dispatchEvent(new Event('input', { bubbles: true }));
|
| 588 |
+
fieldsFilled++;
|
| 589 |
+
console.log(`β
Filled textarea ${index} with caption`);
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
console.log(`π Filled ${fieldsFilled} out of ${fieldsFound} fields`);
|
| 594 |
+
return fieldsFilled > 0;
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
function getFieldLabel(field) {
|
| 598 |
+
// Try to find associated label
|
| 599 |
+
if (field.id) {
|
| 600 |
+
const label = document.querySelector(`label[for="${field.id}"]`);
|
| 601 |
+
if (label) return label.textContent || '';
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
// Look in parent elements for text context
|
| 605 |
+
let parent = field.parentElement;
|
| 606 |
+
let levels = 0;
|
| 607 |
+
while (parent && levels < 3) {
|
| 608 |
+
const labels = parent.querySelectorAll('label, span, div');
|
| 609 |
+
for (const label of labels) {
|
| 610 |
+
const text = label.textContent || '';
|
| 611 |
+
if (text.length > 0 && text.length < 100) {
|
| 612 |
+
return text;
|
| 613 |
+
}
|
| 614 |
+
}
|
| 615 |
+
parent = parent.parentElement;
|
| 616 |
+
levels++;
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
return field.placeholder || '';
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
function loadFromFile(event) {
|
| 623 |
+
const file = event.target.files[0];
|
| 624 |
+
if (!file) return;
|
| 625 |
+
|
| 626 |
+
const reader = new FileReader();
|
| 627 |
+
reader.onload = function(e) {
|
| 628 |
+
try {
|
| 629 |
+
const data = JSON.parse(e.target.result);
|
| 630 |
+
const success = fillVeniceEditionFields(data);
|
| 631 |
+
|
| 632 |
+
if (success) {
|
| 633 |
+
alert(`β
Successfully imported and filled Venice Edition fields!`);
|
| 634 |
+
} else {
|
| 635 |
+
alert('β οΈ Data imported but no matching fields found. Check field labels.');
|
| 636 |
+
}
|
| 637 |
+
} catch (error) {
|
| 638 |
+
console.error('β Import error:', error);
|
| 639 |
+
alert('β Failed to import file: ' + error.message);
|
| 640 |
+
}
|
| 641 |
+
};
|
| 642 |
+
reader.readAsText(file);
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
function loadFromClipboard() {
|
| 646 |
+
navigator.clipboard.readText().then(text => {
|
| 647 |
+
try {
|
| 648 |
+
const data = JSON.parse(text);
|
| 649 |
+
const success = fillVeniceEditionFields(data);
|
| 650 |
+
|
| 651 |
+
if (success) {
|
| 652 |
+
alert(`β
Successfully imported from clipboard and filled Venice Edition fields!`);
|
| 653 |
+
} else {
|
| 654 |
+
alert('β οΈ Data imported but no matching fields found. Check field labels.');
|
| 655 |
+
}
|
| 656 |
+
} catch (error) {
|
| 657 |
+
console.error('β Clipboard import error:', error);
|
| 658 |
+
alert('β Failed to import from clipboard: Invalid JSON format');
|
| 659 |
+
}
|
| 660 |
+
}).catch(err => {
|
| 661 |
+
console.error('β Clipboard read error:', err);
|
| 662 |
+
alert('β Failed to read clipboard: ' + err.message);
|
| 663 |
+
});
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
function createImportButtons() {
|
| 667 |
+
// Remove existing buttons first
|
| 668 |
+
const existingContainer = document.getElementById('venice-import-container');
|
| 669 |
+
if (existingContainer) existingContainer.remove();
|
| 670 |
+
|
| 671 |
+
// Create import button container
|
| 672 |
+
const container = document.createElement('div');
|
| 673 |
+
container.id = 'venice-import-container';
|
| 674 |
+
container.style.cssText = `
|
| 675 |
+
position: fixed;
|
| 676 |
+
top: 20px;
|
| 677 |
+
right: 20px;
|
| 678 |
+
z-index: 9999;
|
| 679 |
+
display: flex;
|
| 680 |
+
flex-direction: column;
|
| 681 |
+
gap: 10px;
|
| 682 |
+
`;
|
| 683 |
+
|
| 684 |
+
// Create file input (hidden)
|
| 685 |
+
const fileInput = document.createElement('input');
|
| 686 |
+
fileInput.type = 'file';
|
| 687 |
+
fileInput.accept = '.json';
|
| 688 |
+
fileInput.style.display = 'none';
|
| 689 |
+
fileInput.addEventListener('change', loadFromFile);
|
| 690 |
+
|
| 691 |
+
// Create import from file button
|
| 692 |
+
const importFileBtn = document.createElement('button');
|
| 693 |
+
importFileBtn.innerHTML = 'π Import from File';
|
| 694 |
+
importFileBtn.style.cssText = `
|
| 695 |
+
background: linear-gradient(135deg, #2e7d32, #388e3c);
|
| 696 |
+
color: white;
|
| 697 |
+
border: none;
|
| 698 |
+
padding: 12px 20px;
|
| 699 |
+
border-radius: 25px;
|
| 700 |
+
font-weight: 600;
|
| 701 |
+
cursor: pointer;
|
| 702 |
+
box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
|
| 703 |
+
transition: all 0.3s ease;
|
| 704 |
+
`;
|
| 705 |
+
|
| 706 |
+
importFileBtn.addEventListener('mouseover', () => {
|
| 707 |
+
importFileBtn.style.transform = 'translateY(-2px)';
|
| 708 |
+
importFileBtn.style.boxShadow = '0 6px 16px rgba(46, 125, 50, 0.4)';
|
| 709 |
+
});
|
| 710 |
+
|
| 711 |
+
importFileBtn.addEventListener('mouseout', () => {
|
| 712 |
+
importFileBtn.style.transform = 'translateY(0)';
|
| 713 |
+
importFileBtn.style.boxShadow = '0 4px 12px rgba(46, 125, 50, 0.3)';
|
| 714 |
+
});
|
| 715 |
+
|
| 716 |
+
importFileBtn.addEventListener('click', () => fileInput.click());
|
| 717 |
+
|
| 718 |
+
// Create import from clipboard button
|
| 719 |
+
const importClipBtn = document.createElement('button');
|
| 720 |
+
importClipBtn.innerHTML = 'π Import from Clipboard';
|
| 721 |
+
importClipBtn.style.cssText = `
|
| 722 |
+
background: linear-gradient(135deg, #1976d2, #1565c0);
|
| 723 |
+
color: white;
|
| 724 |
+
border: none;
|
| 725 |
+
padding: 12px 20px;
|
| 726 |
+
border-radius: 25px;
|
| 727 |
+
font-weight: 600;
|
| 728 |
+
cursor: pointer;
|
| 729 |
+
box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
|
| 730 |
+
transition: all 0.3s ease;
|
| 731 |
+
`;
|
| 732 |
+
|
| 733 |
+
importClipBtn.addEventListener('mouseover', () => {
|
| 734 |
+
importClipBtn.style.transform = 'translateY(-2px)';
|
| 735 |
+
importClipBtn.style.boxShadow = '0 6px 16px rgba(25, 118, 210, 0.4)';
|
| 736 |
+
});
|
| 737 |
+
|
| 738 |
+
importClipBtn.addEventListener('mouseout', () => {
|
| 739 |
+
importClipBtn.style.transform = 'translateY(0)';
|
| 740 |
+
importClipBtn.style.boxShadow = '0 4px 12px rgba(25, 118, 210, 0.3)';
|
| 741 |
+
});
|
| 742 |
+
|
| 743 |
+
importClipBtn.addEventListener('click', loadFromClipboard);
|
| 744 |
+
|
| 745 |
+
// Add elements to container
|
| 746 |
+
container.appendChild(fileInput);
|
| 747 |
+
container.appendChild(importFileBtn);
|
| 748 |
+
container.appendChild(importClipBtn);
|
| 749 |
+
|
| 750 |
+
document.body.appendChild(container);
|
| 751 |
+
console.log('β
Import buttons created and attached to body');
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
// Multiple attempts to create buttons after Gradio loads
|
| 755 |
+
setTimeout(createImportButtons, 1000);
|
| 756 |
+
setTimeout(createImportButtons, 3000);
|
| 757 |
+
setTimeout(createImportButtons, 5000);
|
| 758 |
+
|
| 759 |
+
// Also try when DOM changes (Gradio dynamic loading)
|
| 760 |
+
const observer = new MutationObserver(() => {
|
| 761 |
+
if (!document.getElementById('venice-import-container')) {
|
| 762 |
+
createImportButtons();
|
| 763 |
+
}
|
| 764 |
+
});
|
| 765 |
+
observer.observe(document.body, { childList: true, subtree: true });
|
| 766 |
+
</script>
|
| 767 |
+
"""
|
| 768 |
+
|
| 769 |
# Gradio Interface - TWO COLUMNS ONLY
|
| 770 |
+
with gr.Blocks(title="Venice Edition NSFW Enhancer", theme=gr.themes.Soft(), head=IMPORT_JS) as demo:
|
| 771 |
gr.HTML(TITLE)
|
| 772 |
|
| 773 |
with gr.Row():
|