Spaces:
Sleeping
Sleeping
Update app.py
Browse files51 unmodified lines5253545556575835 unmodified lines949596979899145 unmodified lines2452462472482492501 unmodified line2522532542552562572582592602612622632642652662672682692702712722732742757 unmodified lines283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355268 unmodified lines62462562662751 unmodified linesapi.upload_file(path_or_fileobj=DATA_FILE,path_in_repo=DATA_FILE,repo_id=REPO_ID,repo_type="dataset",token=HF_TOKEN_WRITE,commit_message=f"Автоматическое резервное копирование базы данных {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"35 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Каталог</title><style>* {margin: 0;145 unmodified lines::-webkit-scrollbar-thumb:hover {background: #555;}</style></head><body>1 unmodified line<h1>Каталог товаров</h1><div class="products-grid">{% for product in products %}<a href="{{ url_for('product_detail', index=loop.index0) }}" style="text-decoration: none; color: inherit;"><div class="product">{% if product.get('photos') and product['photos']|length > 0 %}<div class="product-image"><img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ product['photos'][0] }}"alt="{{ product['name'] }}"loading="lazy"></div>{% endif %}<h2>{{ product['name'] }}</h2><div class="product-price">{{ product['price'] }} ₽</div><p class="product-description">{{ product['description'][:100] }}{% if product['description']|length > 100 %}...{% endif %}</p><div class="product-button">Подробнее</div></div></a>{% endfor %}</div></div></body></html>'''7 unmodified linesexcept IndexError:return "Продукт не найден", 404detail_html = '''<!DOCTYPE html><html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>{{ product['name'] }}</title><style>body {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;background-color: #f5f5f5;color: #333;padding: 20px;}.container {max-width: 800px;margin: 0 auto;background: #fff;padding: 20px;border-radius: 8px;box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);}h1 {margin-bottom: 20px;}.photos {display: flex;flex-wrap: wrap;gap: 10px;margin-bottom: 20px;}.photos img {width: calc(50% - 10px);height: auto;border-radius: 5px;}@media (max-width: 600px) {.photos img {width: 100%;}}.back-button {display: inline-block;margin-top: 20px;padding: 10px 15px;background-color: #3498db;color: white;text-decoration: none;border-radius: 5px;}</style></head><body><div class="container"><h1>{{ product['name'] }}</h1><div class="photos">{% if product.get('photos') %}{% for photo in product['photos'] %}<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}" alt="{{ product['name'] }}">{% endfor %}{% endif %}</div><p><strong>Цена:</strong> {{ product['price'] }} ₽</p><p><strong>Описание:</strong> {{ product['description'] }}</p><a href="{{ url_for('catalog') }}" class="back-button">Назад к каталогу</a></div></body></html>'''return render_template_string(detail_html, product=product, repo_id=REPO_ID)268 unmodified linesexcept Exception as e:logging.error(f"Не удалось загрузить базу данных при запуске: {e}")app.run(debug=True, host='0.0.0.0', port=7860)51 unmodified lines52535455565735 unmodified lines93949596979899145 unmodified lines2452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013021 unmodified line3043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663677 unmodified lines375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415268 unmodified lines68468568668751 unmodified linesapi.upload_file(path_or_fileobj=DATA_FILE,path_in_repo=DATA_FILE,repo_type="dataset",token=HF_TOKEN_WRITE,commit_message=f"Автоматическое резервное копирование базы данных {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"35 unmodified lines<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Каталог</title><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"><style>* {margin: 0;145 unmodified lines::-webkit-scrollbar-thumb:hover {background: #555;}/* Modal Styles */.modal {display: none; /* Hidden by default */position: fixed; /* Stay in place */z-index: 1; /* Sit on top */left: 0;top: 0;width: 100%; /* Full width */height: 100%; /* Full height */overflow: auto; /* Enable scroll if needed */background-color: rgba(0,0,0,0.4); /* Black w/ opacity */}.modal-content {position: relative;background-color: #fefefe;margin: 10% auto; /* 15% from the top and centered */padding: 20px;border: 1px solid #888;width: 80%;max-width: 600px;box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);animation-name: animatetop;animation-duration: 0.4s}/* Add Animation */@keyframes animatetop {from {top: -300px; opacity: 0}to {top: 10%; opacity: 1}}/* The Close Button */.close {color: #aaa;float: right;font-size: 28px;font-weight: bold;}.close:hover,.close:focus {color: black;text-decoration: none;cursor: pointer;}/* Image Carousel Styles */.carousel-inner > .carousel-item > img {margin: 0 auto;}</style></head><body>1 unmodified line<h1>Каталог товаров</h1><div class="products-grid">{% for product in products %}<div class="product">{% if product.get('photos') and product['photos']|length > 0 %}<div class="product-image"><img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ product['photos'][0] }}"alt="{{ product['name'] }}"loading="lazy"></div>{% endif %}<h2>{{ product['name'] }}</h2><div class="product-price">{{ product['price'] }} ₽</div><p class="product-description">{{ product['description'][:100] }}{% if product['description']|length > 100 %}...{% endif %}</p><button class="product-button" onclick="openModal({{ loop.index0 }})">Подробнее</button></div>{% endfor %}</div></div><!-- The Modal --><div id="productModal" class="modal"><div class="modal-content"><span class="close" onclick="closeModal()">×</span><div id="modalContent"><!-- Product details will be loaded here --></div></div></div><script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script><script>// Function to open the modalfunction openModal(index) {loadProductDetails(index);document.getElementById('productModal').style.display = "block";}// Function to close the modalfunction closeModal() {document.getElementById('productModal').style.display = "none";}// Function to load product details into the modalfunction loadProductDetails(index) {fetch('/product/' + index).then(response => response.text()).then(data => {document.getElementById('modalContent').innerHTML = data;});}// Close the modal if the user clicks outside of itwindow.onclick = function(event) {if (event.target == document.getElementById('productModal')) {closeModal();}}</script></body></html>'''7 unmodified linesexcept IndexError:return "Продукт не найден", 404detail_html = '''<div class="container"><h2>{{ product['name'] }}</h2><div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"><ol class="carousel-indicators">{% if product.get('photos') %}{% for photo in product['photos'] %}<li data-target="#carouselExampleIndicators" data-slide-to="{{ loop.index0 }}" {% if loop.first %}class="active"{% endif %}></li>{% endfor %}{% endif %}</ol><div class="carousel-inner">{% if product.get('photos') %}{% for photo in product['photos'] %}<div class="carousel-item {% if loop.first %}active{% endif %}"><img class="d-block w-100" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}" alt="{{ product['name'] }}"></div>{% endfor %}{% else %}<div class="carousel-item active"><img class="d-block w-100" src="https://via.placeholder.com/300" alt="No Image"></div>{% endif %}</div><a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"><span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"><span class="carousel-control-next-icon" aria-hidden="true"></span><span class="sr-only">Next</span></a></div><p><strong>Цена:</strong> {{ product['price'] }} ₽</p><p><strong>Описание:</strong> {{ product['description'] }}</p></div>'''return render_template_string(detail_html, product=product, repo_id=REPO_ID)268 unmodified linesexcept Exception as e:logging.error(f"Не удалось загрузить базу данных при запуске: {e}")app.run(debug=True, host='0.0.0.0', port=7860)
app.py+137-77