Kgshop commited on
Commit
4ec3f42
·
verified ·
1 Parent(s): c65edbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -35
app.py CHANGED
@@ -20,6 +20,7 @@ load_dotenv()
20
  app = Flask(__name__)
21
  app.secret_key = 'your_unique_secret_key_gippo_312_shop_54321_no_login_synkris'
22
  DATA_FILE = 'data.json'
 
23
 
24
  SYNC_FILES = [DATA_FILE]
25
 
@@ -34,7 +35,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
34
 
35
  def download_db_from_hf(specific_file=None, retries=DOWNLOAD_RETRIES, delay=DOWNLOAD_DELAY):
36
  if not HF_TOKEN_READ and not HF_TOKEN_WRITE:
37
- pass
38
  token_to_use = HF_TOKEN_READ if HF_TOKEN_READ else HF_TOKEN_WRITE
39
  files_to_download = [specific_file] if specific_file else SYNC_FILES
40
  all_successful = True
@@ -55,7 +56,8 @@ def download_db_from_hf(specific_file=None, retries=DOWNLOAD_RETRIES, delay=DOWN
55
  success = True
56
  break
57
  except RepositoryNotFoundError:
58
- return False
 
59
  except HfHubHTTPError as e:
60
  if e.response.status_code == 404:
61
  if attempt == 0 and not os.path.exists(file_name):
@@ -106,31 +108,38 @@ def periodic_backup():
106
  upload_db_to_hf()
107
 
108
  def load_data():
109
- try:
110
- with open(DATA_FILE, 'r', encoding='utf-8') as f:
111
- data = json.load(f)
112
- if not isinstance(data, dict):
113
- data = {}
114
- except (FileNotFoundError, json.JSONDecodeError):
115
- if download_db_from_hf(specific_file=DATA_FILE):
116
- try:
117
- with open(DATA_FILE, 'r', encoding='utf-8') as f:
118
- data = json.load(f)
119
- if not isinstance(data, dict):
120
  data = {}
121
- except (FileNotFoundError, json.JSONDecodeError):
122
- data = {}
123
- else:
 
 
124
  data = {}
 
 
 
125
  return data
126
 
127
  def save_data(data):
128
  try:
129
- with open(DATA_FILE, 'w', encoding='utf-8') as file:
130
  json.dump(data, file, ensure_ascii=False, indent=4)
 
131
  upload_db_to_hf(specific_file=DATA_FILE)
132
  except Exception:
133
- pass
 
134
 
135
  LANDING_PAGE_TEMPLATE = '''
136
  <!DOCTYPE html>
@@ -652,7 +661,7 @@ select option {
652
  padding: 12px 14px;
653
  }
654
 
655
- .checkbox-container input {
656
  margin-right: 10px;
657
  }
658
 
@@ -969,6 +978,13 @@ select option {
969
  Сгенерировать коллаж с увеличенными деталями (ткань, фурнитура)
970
  </label>
971
  </div>
 
 
 
 
 
 
 
972
  <div class="checkbox-container">
973
  <input type="checkbox" id="multiple_variants_checkbox">
974
  <label for="multiple_variants_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
@@ -1158,6 +1174,13 @@ select option {
1158
  Сгенерировать коллаж с увеличенными деталями (ткань, фурнитура)
1159
  </label>
1160
  </div>
 
 
 
 
 
 
 
1161
  <div class="checkbox-container">
1162
  <input type="checkbox" id="child_multiple_variants_checkbox">
1163
  <label for="child_multiple_variants_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
@@ -1239,12 +1262,19 @@ select option {
1239
  </div>
1240
  <div class="form-group full-width">
1241
  <label class="checkbox-label">Детали товара</label>
1242
- <div class="checkbox-container">
1243
  <input type="checkbox" id="object_details_checkbox">
1244
  <label for="object_details_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
1245
  Сгенерировать коллаж с увеличенными деталями (текстура, материалы)
1246
  </label>
1247
  </div>
 
 
 
 
 
 
 
1248
  </div>
1249
  <div class="form-group full-width">
1250
  <label class="checkbox-label">Креативность</label>
@@ -1340,7 +1370,7 @@ function autoAdjustDefaults() {
1340
 
1341
  function toggleMyModelMode() {
1342
  const isMyModel = document.getElementById('my_model_checkbox').checked;
1343
- const fieldsToToggle = ['gender', 'age', 'nationality', 'hairColor', 'hairstyle', 'emotion', 'clothing_details_checkbox', 'multiple_variants_checkbox'];
1344
 
1345
  fieldsToToggle.forEach(fieldId => {
1346
  const element = document.getElementById(fieldId);
@@ -1360,6 +1390,12 @@ function toggleCreativeMode() {
1360
  document.getElementById('object_background').disabled = isCreative;
1361
  }
1362
 
 
 
 
 
 
 
1363
  function setupClickableSelectors() {
1364
  const selectorGroups = document.querySelectorAll('.style-grid, .aspect-ratio-grid');
1365
  selectorGroups.forEach(container => {
@@ -1414,7 +1450,15 @@ async function processAndOpen() {
1414
  aspectRatio = document.querySelector('#aspectRatioSelectorObject .aspect-ratio-btn.active').dataset.value;
1415
  }
1416
 
 
 
1417
  if (currentMode === 'model') {
 
 
 
 
 
 
1418
  const isMyModel = document.getElementById('my_model_checkbox').checked;
1419
  const generateDetailsCollage = document.getElementById('clothing_details_checkbox').checked;
1420
  const generateMultipleVariants = document.getElementById('multiple_variants_checkbox').checked;
@@ -1471,11 +1515,17 @@ ${model_characteristics_base}
1471
  clothing_focus:: HIGHEST PRIORITY - The model (or models) are wearing EXACTLY: ${details}. If multiple models are present, each wears a different color or minor style variant of this primary clothing description. This description is absolute and must be followed with 1000% accuracy, overriding any other assumptions. Physical accuracy of the described items is critical.
1472
  texture_&_material_fidelity:: Extreme macro precision on textiles. Render the fabric weave, individual threads, visible stitching, material weight, realistic creases and folds, tactile surface imperfections like denim twill or wool fibers, and how light interacts with the fabric as described in the clothing focus.
1473
  human_realism_details:: Capture hyper-realistic skin texture, showing pores, vellus hair, and subtle imperfections. Avoid any plastic or airbrushed look. Expertly sculpted light highlights the bone structure. Eyes must have realistic reflections and depth.
1474
- scene_environment:: ${location}, creating a sophisticated and aspirational atmosphere.
1475
  technical:: Masterpiece professional photograph, ${light} meticulously crafted to sculpt the subject with soft shadows and catchlights in eyes, shot on ${camera}, 8k UHD, razor-sharp focus, breathtaking detail, uncompressed, color graded to perfection.`;
1476
  }
1477
 
1478
  } else if (currentMode === 'children') {
 
 
 
 
 
 
1479
  const generateDetailsCollage = document.getElementById('child_clothing_details_checkbox').checked;
1480
  const generateMultipleVariants = document.getElementById('child_multiple_variants_checkbox').checked;
1481
  const style = document.getElementById('child_style').value;
@@ -1530,7 +1580,7 @@ subject:: ${subject} The photograph must look like a cover shot for a high-end c
1530
  clothing_focus:: CRITICAL INSTRUCTION - The children are wearing EXACTLY: ${clothing_details}. Each child wears a different color variant of this outfit. This description must be rendered with 1000% fidelity. This is the most important instruction.
1531
  texture_&_material_fidelity:: Macro-level detail on clothing textures as described above. Focus on the weave of cotton, the softness of wool fibers, the texture of denim. Show realistic wrinkles and creases from movement. Absolute texture fidelity to the description is crucial.
1532
  human_realism_details:: Capture the pure, innocent beauty of the children. Hyper-realistic, dewy skin with a natural glow and visible texture, not airbrushed. The light should have a painterly, almost magical quality. Eyes must be expressive, with realistic reflections and depth. Individual hair strands should be visible.
1533
- scene_activity:: ${pose_info} The location is ${location}, creating a whimsical and high-end narrative.
1534
  technical:: Masterpiece photograph, ${light} creating a magical and soft atmosphere, shot on Fujifilm XT4, 56mm F1.2 lens, 8k, tack sharp focus, impeccable detail, perfect color grading, looks like a real captured moment of wonder from a luxury campaign.`;
1535
 
1536
  } else {
@@ -1540,11 +1590,17 @@ subject:: ${subject} The photograph must look like a cover shot for a high-end c
1540
  clothing_focus:: CRITICAL INSTRUCTION - The child is wearing EXACTLY: ${clothing_details}. This description must be rendered with 1000% fidelity. For example, if 'anti-scratch mittens' are mentioned, the hands MUST be covered. If 'open-toed sandals' are mentioned, the toes MUST be visible. This is the most important instruction.
1541
  texture_&_material_fidelity:: Macro-level detail on clothing textures as described above. Focus on the weave of cotton, the softness of wool fibers, the texture of denim. Show realistic wrinkles and creases from movement. Absolute texture fidelity to the description is crucial.
1542
  human_realism_details:: Capture the pure, innocent beauty of the child. Hyper-realistic, dewy skin with a natural glow and visible texture, not airbrushed. The light should have a painterly, almost magical quality. Eyes must be expressive, with realistic reflections and depth. Individual hair strands should be visible.
1543
- scene_activity:: ${pose_info} The location is ${location}, creating a whimsical and high-end narrative.
1544
  technical:: Masterpiece photograph, ${light} creating a magical and soft atmosphere, shot on Fujifilm XT4, 56mm F1.2 lens, 8k, tack sharp focus, impeccable detail, perfect color grading, looks like a real captured moment of wonder from a luxury campaign.`;
1545
  }
1546
 
1547
- } else {
 
 
 
 
 
 
1548
  const generateDetailsCollage = document.getElementById('object_details_checkbox').checked;
1549
  const objectName = document.getElementById('object_name').value || "a product";
1550
  const objectStyle = document.getElementById('object_style').value;
@@ -1567,14 +1623,14 @@ main_image_description:: A medium shot of the luxury product: ${objectName}. Pla
1567
  detail_shot_1_description:: A hyper-detailed macro photograph focusing on the raw texture of the product's primary material.
1568
  detail_shot_2_description:: An extreme close-up of a key hardware detail from the product, such as an intricate logo, a metallic element, or a unique engraving.
1569
  detail_shot_3_description:: A close-up shot showcasing the quality of the craftsmanship, focusing on the joints, stitching, or seams of the product described above.
1570
- environment_and_lighting:: The main image lighting is ${objectLighting}.
1571
  technical:: Each individual image in this collage is an 8k UHD advertisement-grade masterpiece with flawless focus.`;
1572
  } else {
1573
  fullPrompt = `${envKeyword}, style:: Luxury product advertising, ${objectStyle}, sophisticated, sleek, ultra-photorealistic.
1574
  subject:: A breathtaking, hyper-realistic photograph of the luxury product: ${objectName}. The image must evoke desire and exclusivity, looking like a real, professionally shot advertisement.
1575
  material_focus:: Achieve 1000% physical accuracy with an emphasis on perfection. Render pristine, flawless surfaces with micro-scratches and realistic imperfections. Showcase the intricate details of the material grain, polished metal sheen with fingerprints, or crystal-clear refractions. Even microscopic dust particles should look clean and perfect.
1576
  scene_context:: Placed ${background}. Additional details: It is MANDATORY to include the following details with perfect realism: ${objectDetails}. This description has the highest priority.
1577
- composition:: ${objectComposition}, creating a powerful and elegant visual statement.
1578
  technical:: Advertisement-grade photograph, ${objectLighting} designed to accentuate the product's luxury form and textures, 8k UHD resolution, flawless focus, extreme macro detail, advanced ray-traced reflections and caustics, impeccably clean, exudes quality and high-end appeal, masterpiece.`;
1579
  }
1580
  }
@@ -1627,6 +1683,7 @@ def admhosto():
1627
  archived_environments = []
1628
 
1629
  for env_id, env_data in data.items():
 
1630
  env_item = {
1631
  "id": env_id,
1632
  "keyword": env_data.get("keyword", "N/A"),
@@ -1640,8 +1697,8 @@ def admhosto():
1640
  else:
1641
  active_environments.append(env_item)
1642
 
1643
- active_environments.sort(key=lambda x: x['created_at'], reverse=True)
1644
- archived_environments.sort(key=lambda x: x['created_at'], reverse=True)
1645
 
1646
  return render_template_string(ADMHOSTO_TEMPLATE, active_environments=active_environments, archived_environments=archived_environments)
1647
 
@@ -1759,7 +1816,7 @@ def get_env_stats(env_id):
1759
  def serve_env(env_id):
1760
  data = load_data()
1761
  env_data = data.get(env_id)
1762
- if not env_data or env_data.get("archived"):
1763
  return "Среда не найдена или заархивирована.", 404
1764
 
1765
  keyword = env_data.get("keyword", "")
@@ -1767,12 +1824,12 @@ def serve_env(env_id):
1767
 
1768
  current_log = {
1769
  "time": datetime.utcnow().isoformat(),
1770
- "ip": request.remote_addr,
1771
- "ua": request.headers.get('User-Agent')[:150]
1772
  }
1773
 
1774
  env_data['hits'] = env_data.get('hits', 0) + 1
1775
- if 'logs' not in env_data:
1776
  env_data['logs'] = []
1777
 
1778
  env_data['logs'].append(current_log)
@@ -1820,7 +1877,7 @@ def serve_env(env_id):
1820
  save_data(data)
1821
 
1822
  resp = make_response(render_template_string(SYNKRIS_LOOK_TEMPLATE, keyword=keyword))
1823
- resp.set_cookie(f'access_token_{env_id}', new_token, max_age=31536000, httponly=True)
1824
  return resp
1825
 
1826
  if __name__ == '__main__':
@@ -1829,6 +1886,6 @@ if __name__ == '__main__':
1829
  backup_thread = threading.Thread(target=periodic_backup, daemon=True)
1830
  backup_thread.start()
1831
  else:
1832
- pass
1833
  port = int(os.environ.get('PORT', 7860))
1834
  app.run(debug=False, host='0.0.0.0', port=port)
 
20
  app = Flask(__name__)
21
  app.secret_key = 'your_unique_secret_key_gippo_312_shop_54321_no_login_synkris'
22
  DATA_FILE = 'data.json'
23
+ DATA_FILE_TEMP = 'data.json.tmp'
24
 
25
  SYNC_FILES = [DATA_FILE]
26
 
 
35
 
36
  def download_db_from_hf(specific_file=None, retries=DOWNLOAD_RETRIES, delay=DOWNLOAD_DELAY):
37
  if not HF_TOKEN_READ and not HF_TOKEN_WRITE:
38
+ return False
39
  token_to_use = HF_TOKEN_READ if HF_TOKEN_READ else HF_TOKEN_WRITE
40
  files_to_download = [specific_file] if specific_file else SYNC_FILES
41
  all_successful = True
 
56
  success = True
57
  break
58
  except RepositoryNotFoundError:
59
+ all_successful = False
60
+ break
61
  except HfHubHTTPError as e:
62
  if e.response.status_code == 404:
63
  if attempt == 0 and not os.path.exists(file_name):
 
108
  upload_db_to_hf()
109
 
110
  def load_data():
111
+ data = {}
112
+ if os.path.exists(DATA_FILE):
113
+ try:
114
+ with open(DATA_FILE, 'r', encoding='utf-8') as f:
115
+ data = json.load(f)
116
+ except json.JSONDecodeError:
117
+ if download_db_from_hf(specific_file=DATA_FILE):
118
+ try:
119
+ with open(DATA_FILE, 'r', encoding='utf-8') as f:
120
+ data = json.load(f)
121
+ except (FileNotFoundError, json.JSONDecodeError):
122
  data = {}
123
+ elif download_db_from_hf(specific_file=DATA_FILE):
124
+ try:
125
+ with open(DATA_FILE, 'r', encoding='utf-8') as f:
126
+ data = json.load(f)
127
+ except (FileNotFoundError, json.JSONDecodeError):
128
  data = {}
129
+
130
+ if not isinstance(data, dict):
131
+ data = {}
132
  return data
133
 
134
  def save_data(data):
135
  try:
136
+ with open(DATA_FILE_TEMP, 'w', encoding='utf-8') as file:
137
  json.dump(data, file, ensure_ascii=False, indent=4)
138
+ os.replace(DATA_FILE_TEMP, DATA_FILE)
139
  upload_db_to_hf(specific_file=DATA_FILE)
140
  except Exception:
141
+ if os.path.exists(DATA_FILE_TEMP):
142
+ os.remove(DATA_FILE_TEMP)
143
 
144
  LANDING_PAGE_TEMPLATE = '''
145
  <!DOCTYPE html>
 
661
  padding: 12px 14px;
662
  }
663
 
664
+ .checkbox-container input[type="checkbox"] {
665
  margin-right: 10px;
666
  }
667
 
 
978
  Сгенерировать коллаж с увеличенными деталями (ткань, фурнитура)
979
  </label>
980
  </div>
981
+ <div class="checkbox-container" style="margin-bottom: 10px;">
982
+ <input type="checkbox" id="text_overlay_checkbox" onchange="toggleTextInput('text_overlay_checkbox', 'text_overlay_input')">
983
+ <label for="text_overlay_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
984
+ Наложение текста
985
+ </label>
986
+ </div>
987
+ <input type="text" id="text_overlay_input" placeholder="Введите текст через запятую..." style="display: none; margin-top: 10px;">
988
  <div class="checkbox-container">
989
  <input type="checkbox" id="multiple_variants_checkbox">
990
  <label for="multiple_variants_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
 
1174
  Сгенерировать коллаж с увеличенными деталями (ткань, фурнитура)
1175
  </label>
1176
  </div>
1177
+ <div class="checkbox-container" style="margin-bottom: 10px;">
1178
+ <input type="checkbox" id="child_text_overlay_checkbox" onchange="toggleTextInput('child_text_overlay_checkbox', 'child_text_overlay_input')">
1179
+ <label for="child_text_overlay_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
1180
+ Наложение текста
1181
+ </label>
1182
+ </div>
1183
+ <input type="text" id="child_text_overlay_input" placeholder="Введите текст через запятую..." style="display: none; margin-top: 10px;">
1184
  <div class="checkbox-container">
1185
  <input type="checkbox" id="child_multiple_variants_checkbox">
1186
  <label for="child_multiple_variants_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
 
1262
  </div>
1263
  <div class="form-group full-width">
1264
  <label class="checkbox-label">Детали товара</label>
1265
+ <div class="checkbox-container" style="margin-bottom: 10px;">
1266
  <input type="checkbox" id="object_details_checkbox">
1267
  <label for="object_details_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
1268
  Сгенерировать коллаж с увеличенными деталями (текстура, материалы)
1269
  </label>
1270
  </div>
1271
+ <div class="checkbox-container" style="margin-bottom: 10px;">
1272
+ <input type="checkbox" id="object_text_overlay_checkbox" onchange="toggleTextInput('object_text_overlay_checkbox', 'object_text_overlay_input')">
1273
+ <label for="object_text_overlay_checkbox" style="color: var(--text); text-transform: none; letter-spacing: 0;">
1274
+ Наложение текста
1275
+ </label>
1276
+ </div>
1277
+ <input type="text" id="object_text_overlay_input" placeholder="Введите текст через запятую..." style="display: none; margin-top: 10px;">
1278
  </div>
1279
  <div class="form-group full-width">
1280
  <label class="checkbox-label">Креативность</label>
 
1370
 
1371
  function toggleMyModelMode() {
1372
  const isMyModel = document.getElementById('my_model_checkbox').checked;
1373
+ const fieldsToToggle = ['gender', 'age', 'nationality', 'hairColor', 'hairstyle', 'emotion', 'clothing_details_checkbox', 'multiple_variants_checkbox', 'text_overlay_checkbox'];
1374
 
1375
  fieldsToToggle.forEach(fieldId => {
1376
  const element = document.getElementById(fieldId);
 
1390
  document.getElementById('object_background').disabled = isCreative;
1391
  }
1392
 
1393
+ function toggleTextInput(checkboxId, inputId) {
1394
+ const checkbox = document.getElementById(checkboxId);
1395
+ const input = document.getElementById(inputId);
1396
+ input.style.display = checkbox.checked ? 'block' : 'none';
1397
+ }
1398
+
1399
  function setupClickableSelectors() {
1400
  const selectorGroups = document.querySelectorAll('.style-grid, .aspect-ratio-grid');
1401
  selectorGroups.forEach(container => {
 
1450
  aspectRatio = document.querySelector('#aspectRatioSelectorObject .aspect-ratio-btn.active').dataset.value;
1451
  }
1452
 
1453
+ let textOverlayPrompt = '';
1454
+
1455
  if (currentMode === 'model') {
1456
+ const useTextOverlay = document.getElementById('text_overlay_checkbox').checked;
1457
+ const textOverlayValue = document.getElementById('text_overlay_input').value;
1458
+ if(useTextOverlay && textOverlayValue) {
1459
+ textOverlayPrompt = ` Typography: The image must include a beautifully integrated text overlay that says '${textOverlayValue}'. The typography should be elegant and match the high-fashion aesthetic of the scene, complementing the composition without obstructing the main subject.`;
1460
+ }
1461
+
1462
  const isMyModel = document.getElementById('my_model_checkbox').checked;
1463
  const generateDetailsCollage = document.getElementById('clothing_details_checkbox').checked;
1464
  const generateMultipleVariants = document.getElementById('multiple_variants_checkbox').checked;
 
1515
  clothing_focus:: HIGHEST PRIORITY - The model (or models) are wearing EXACTLY: ${details}. If multiple models are present, each wears a different color or minor style variant of this primary clothing description. This description is absolute and must be followed with 1000% accuracy, overriding any other assumptions. Physical accuracy of the described items is critical.
1516
  texture_&_material_fidelity:: Extreme macro precision on textiles. Render the fabric weave, individual threads, visible stitching, material weight, realistic creases and folds, tactile surface imperfections like denim twill or wool fibers, and how light interacts with the fabric as described in the clothing focus.
1517
  human_realism_details:: Capture hyper-realistic skin texture, showing pores, vellus hair, and subtle imperfections. Avoid any plastic or airbrushed look. Expertly sculpted light highlights the bone structure. Eyes must have realistic reflections and depth.
1518
+ scene_environment:: ${location}, creating a sophisticated and aspirational atmosphere.${textOverlayPrompt}
1519
  technical:: Masterpiece professional photograph, ${light} meticulously crafted to sculpt the subject with soft shadows and catchlights in eyes, shot on ${camera}, 8k UHD, razor-sharp focus, breathtaking detail, uncompressed, color graded to perfection.`;
1520
  }
1521
 
1522
  } else if (currentMode === 'children') {
1523
+ const useTextOverlay = document.getElementById('child_text_overlay_checkbox').checked;
1524
+ const textOverlayValue = document.getElementById('child_text_overlay_input').value;
1525
+ if(useTextOverlay && textOverlayValue) {
1526
+ textOverlayPrompt = ` Typography: The image should feature a charming and playful text overlay with the words '${textOverlayValue}'. The font and style should feel appropriate for a children's brand, being clear and aesthetically pleasing.`;
1527
+ }
1528
+
1529
  const generateDetailsCollage = document.getElementById('child_clothing_details_checkbox').checked;
1530
  const generateMultipleVariants = document.getElementById('child_multiple_variants_checkbox').checked;
1531
  const style = document.getElementById('child_style').value;
 
1580
  clothing_focus:: CRITICAL INSTRUCTION - The children are wearing EXACTLY: ${clothing_details}. Each child wears a different color variant of this outfit. This description must be rendered with 1000% fidelity. This is the most important instruction.
1581
  texture_&_material_fidelity:: Macro-level detail on clothing textures as described above. Focus on the weave of cotton, the softness of wool fibers, the texture of denim. Show realistic wrinkles and creases from movement. Absolute texture fidelity to the description is crucial.
1582
  human_realism_details:: Capture the pure, innocent beauty of the children. Hyper-realistic, dewy skin with a natural glow and visible texture, not airbrushed. The light should have a painterly, almost magical quality. Eyes must be expressive, with realistic reflections and depth. Individual hair strands should be visible.
1583
+ scene_activity:: ${pose_info} The location is ${location}, creating a whimsical and high-end narrative.${textOverlayPrompt}
1584
  technical:: Masterpiece photograph, ${light} creating a magical and soft atmosphere, shot on Fujifilm XT4, 56mm F1.2 lens, 8k, tack sharp focus, impeccable detail, perfect color grading, looks like a real captured moment of wonder from a luxury campaign.`;
1585
 
1586
  } else {
 
1590
  clothing_focus:: CRITICAL INSTRUCTION - The child is wearing EXACTLY: ${clothing_details}. This description must be rendered with 1000% fidelity. For example, if 'anti-scratch mittens' are mentioned, the hands MUST be covered. If 'open-toed sandals' are mentioned, the toes MUST be visible. This is the most important instruction.
1591
  texture_&_material_fidelity:: Macro-level detail on clothing textures as described above. Focus on the weave of cotton, the softness of wool fibers, the texture of denim. Show realistic wrinkles and creases from movement. Absolute texture fidelity to the description is crucial.
1592
  human_realism_details:: Capture the pure, innocent beauty of the child. Hyper-realistic, dewy skin with a natural glow and visible texture, not airbrushed. The light should have a painterly, almost magical quality. Eyes must be expressive, with realistic reflections and depth. Individual hair strands should be visible.
1593
+ scene_activity:: ${pose_info} The location is ${location}, creating a whimsical and high-end narrative.${textOverlayPrompt}
1594
  technical:: Masterpiece photograph, ${light} creating a magical and soft atmosphere, shot on Fujifilm XT4, 56mm F1.2 lens, 8k, tack sharp focus, impeccable detail, perfect color grading, looks like a real captured moment of wonder from a luxury campaign.`;
1595
  }
1596
 
1597
+ } else { // objectMode
1598
+ const useTextOverlay = document.getElementById('object_text_overlay_checkbox').checked;
1599
+ const textOverlayValue = document.getElementById('object_text_overlay_input').value;
1600
+ if(useTextOverlay && textOverlayValue) {
1601
+ textOverlayPrompt = ` Typography: The final image must incorporate the text '${textOverlayValue}' in a sophisticated and modern font. The text should be artfully placed to enhance the product's branding, complementing the overall composition and aesthetic.`;
1602
+ }
1603
+
1604
  const generateDetailsCollage = document.getElementById('object_details_checkbox').checked;
1605
  const objectName = document.getElementById('object_name').value || "a product";
1606
  const objectStyle = document.getElementById('object_style').value;
 
1623
  detail_shot_1_description:: A hyper-detailed macro photograph focusing on the raw texture of the product's primary material.
1624
  detail_shot_2_description:: An extreme close-up of a key hardware detail from the product, such as an intricate logo, a metallic element, or a unique engraving.
1625
  detail_shot_3_description:: A close-up shot showcasing the quality of the craftsmanship, focusing on the joints, stitching, or seams of the product described above.
1626
+ environment_and_lighting:: The main image lighting is ${objectLighting}.${textOverlayPrompt}
1627
  technical:: Each individual image in this collage is an 8k UHD advertisement-grade masterpiece with flawless focus.`;
1628
  } else {
1629
  fullPrompt = `${envKeyword}, style:: Luxury product advertising, ${objectStyle}, sophisticated, sleek, ultra-photorealistic.
1630
  subject:: A breathtaking, hyper-realistic photograph of the luxury product: ${objectName}. The image must evoke desire and exclusivity, looking like a real, professionally shot advertisement.
1631
  material_focus:: Achieve 1000% physical accuracy with an emphasis on perfection. Render pristine, flawless surfaces with micro-scratches and realistic imperfections. Showcase the intricate details of the material grain, polished metal sheen with fingerprints, or crystal-clear refractions. Even microscopic dust particles should look clean and perfect.
1632
  scene_context:: Placed ${background}. Additional details: It is MANDATORY to include the following details with perfect realism: ${objectDetails}. This description has the highest priority.
1633
+ composition:: ${objectComposition}, creating a powerful and elegant visual statement.${textOverlayPrompt}
1634
  technical:: Advertisement-grade photograph, ${objectLighting} designed to accentuate the product's luxury form and textures, 8k UHD resolution, flawless focus, extreme macro detail, advanced ray-traced reflections and caustics, impeccably clean, exudes quality and high-end appeal, masterpiece.`;
1635
  }
1636
  }
 
1683
  archived_environments = []
1684
 
1685
  for env_id, env_data in data.items():
1686
+ if not isinstance(env_data, dict): continue
1687
  env_item = {
1688
  "id": env_id,
1689
  "keyword": env_data.get("keyword", "N/A"),
 
1697
  else:
1698
  active_environments.append(env_item)
1699
 
1700
+ active_environments.sort(key=lambda x: x.get('created_at', ''), reverse=True)
1701
+ archived_environments.sort(key=lambda x: x.get('created_at', ''), reverse=True)
1702
 
1703
  return render_template_string(ADMHOSTO_TEMPLATE, active_environments=active_environments, archived_environments=archived_environments)
1704
 
 
1816
  def serve_env(env_id):
1817
  data = load_data()
1818
  env_data = data.get(env_id)
1819
+ if not env_data or not isinstance(env_data, dict) or env_data.get("archived"):
1820
  return "Среда не найдена или заархивирована.", 404
1821
 
1822
  keyword = env_data.get("keyword", "")
 
1824
 
1825
  current_log = {
1826
  "time": datetime.utcnow().isoformat(),
1827
+ "ip": request.headers.get('X-Forwarded-For', request.remote_addr),
1828
+ "ua": request.headers.get('User-Agent', '')[:150]
1829
  }
1830
 
1831
  env_data['hits'] = env_data.get('hits', 0) + 1
1832
+ if 'logs' not in env_data or not isinstance(env_data.get('logs'), list):
1833
  env_data['logs'] = []
1834
 
1835
  env_data['logs'].append(current_log)
 
1877
  save_data(data)
1878
 
1879
  resp = make_response(render_template_string(SYNKRIS_LOOK_TEMPLATE, keyword=keyword))
1880
+ resp.set_cookie(f'access_token_{env_id}', new_token, max_age=31536000, httponly=True, samesite='Lax')
1881
  return resp
1882
 
1883
  if __name__ == '__main__':
 
1886
  backup_thread = threading.Thread(target=periodic_backup, daemon=True)
1887
  backup_thread.start()
1888
  else:
1889
+ logging.info("HF_TOKEN_WRITE is not set. Periodic backup is disabled.")
1890
  port = int(os.environ.get('PORT', 7860))
1891
  app.run(debug=False, host='0.0.0.0', port=port)