Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import time
|
|
| 7 |
from datetime import datetime
|
| 8 |
from huggingface_hub import HfApi, hf_hub_download
|
| 9 |
from werkzeug.utils import secure_filename
|
|
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
app.secret_key = 'supersecretkey' # Замените на безопасный ключ в продакшене
|
|
@@ -228,8 +229,8 @@ def video_feed():
|
|
| 228 |
.sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; z-index: 1000; }
|
| 229 |
.sidebar.active { left: 0; }
|
| 230 |
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
|
| 231 |
-
.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); text-decoration: none; color: #2d3748; }
|
| 232 |
-
.video-
|
| 233 |
.auth-links, .upload-btn, .logout-btn, .profile-link { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-align: center; text-decoration: none; border-radius: 8px; }
|
| 234 |
.logout-btn { background: #ef4444; }
|
| 235 |
.profile-link { background: #10b981; }
|
|
@@ -241,7 +242,7 @@ def video_feed():
|
|
| 241 |
.menu-btn { display: block; }
|
| 242 |
.video-grid { grid-template-columns: 1fr; }
|
| 243 |
.video-item { padding: 10px; }
|
| 244 |
-
.video-
|
| 245 |
}
|
| 246 |
</style>
|
| 247 |
</head>
|
|
@@ -263,7 +264,9 @@ def video_feed():
|
|
| 263 |
<div class="video-grid">
|
| 264 |
{% for video in videos %}
|
| 265 |
<a href="{{ url_for('video_page', video_id=video['id']) }}" class="video-item">
|
| 266 |
-
<
|
|
|
|
|
|
|
| 267 |
<h2>{{ video['title'] }}</h2>
|
| 268 |
<p>{{ video['description'] }}</p>
|
| 269 |
<p>Загрузил: {{ video['uploader'] }} | {{ video['upload_date'] }}</p>
|
|
@@ -275,11 +278,21 @@ def video_feed():
|
|
| 275 |
function toggleSidebar() {
|
| 276 |
document.getElementById('sidebar').classList.toggle('active');
|
| 277 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
</script>
|
| 279 |
</body>
|
| 280 |
</html>
|
| 281 |
'''
|
| 282 |
-
return render_template_string(html, videos=videos, is_authenticated=is_authenticated, username=username)
|
| 283 |
|
| 284 |
# Страница отдельного видео
|
| 285 |
@app.route('/video/<video_id>')
|
|
@@ -388,7 +401,7 @@ def profile():
|
|
| 388 |
.container { max-width: 800px; margin: 0 auto; padding-left: 220px; transition: padding-left 0.3s; }
|
| 389 |
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
|
| 390 |
.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
|
| 391 |
-
.video-
|
| 392 |
.upload-btn, .delete-btn, .profile-link, .logout-btn { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }
|
| 393 |
.delete-btn { background: #ef4444; border: none; cursor: pointer; }
|
| 394 |
.profile-link { background: #10b981; }
|
|
@@ -401,7 +414,7 @@ def profile():
|
|
| 401 |
.menu-btn { display: block; }
|
| 402 |
.video-grid { grid-template-columns: 1fr; }
|
| 403 |
.video-item { padding: 10px; }
|
| 404 |
-
.video-
|
| 405 |
.upload-btn, .delete-btn { font-size: 14px; padding: 8px; }
|
| 406 |
}
|
| 407 |
</style>
|
|
@@ -423,7 +436,9 @@ def profile():
|
|
| 423 |
{% for video in user_videos %}
|
| 424 |
<div class="video-item">
|
| 425 |
<a href="{{ url_for('video_page', video_id=video['id']) }}">
|
| 426 |
-
<
|
|
|
|
|
|
|
| 427 |
<h3>{{ video['title'] }}</h3>
|
| 428 |
</a>
|
| 429 |
<p>{{ video['description'] }}</p>
|
|
@@ -443,11 +458,21 @@ def profile():
|
|
| 443 |
function toggleSidebar() {
|
| 444 |
document.getElementById('sidebar').classList.toggle('active');
|
| 445 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
</script>
|
| 447 |
</body>
|
| 448 |
</html>
|
| 449 |
'''
|
| 450 |
-
return render_template_string(html, username=username, user_videos=user_videos)
|
| 451 |
|
| 452 |
# Страница загрузки видео
|
| 453 |
@app.route('/upload', methods=['GET', 'POST'])
|
|
|
|
| 7 |
from datetime import datetime
|
| 8 |
from huggingface_hub import HfApi, hf_hub_download
|
| 9 |
from werkzeug.utils import secure_filename
|
| 10 |
+
import random
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
app.secret_key = 'supersecretkey' # Замените на безопасный ключ в продакшене
|
|
|
|
| 229 |
.sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; z-index: 1000; }
|
| 230 |
.sidebar.active { left: 0; }
|
| 231 |
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
|
| 232 |
+
.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); text-decoration: none; color: #2d3748; position: relative; }
|
| 233 |
+
.video-preview { width: 100%; border-radius: 8px; height: 200px; object-fit: cover; }
|
| 234 |
.auth-links, .upload-btn, .logout-btn, .profile-link { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-align: center; text-decoration: none; border-radius: 8px; }
|
| 235 |
.logout-btn { background: #ef4444; }
|
| 236 |
.profile-link { background: #10b981; }
|
|
|
|
| 242 |
.menu-btn { display: block; }
|
| 243 |
.video-grid { grid-template-columns: 1fr; }
|
| 244 |
.video-item { padding: 10px; }
|
| 245 |
+
.video-preview { height: 150px; }
|
| 246 |
}
|
| 247 |
</style>
|
| 248 |
</head>
|
|
|
|
| 264 |
<div class="video-grid">
|
| 265 |
{% for video in videos %}
|
| 266 |
<a href="{{ url_for('video_page', video_id=video['id']) }}" class="video-item">
|
| 267 |
+
<video class="video-preview" preload="metadata" muted>
|
| 268 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/videos/{{ video['filename'] }}" type="video/mp4">
|
| 269 |
+
</video>
|
| 270 |
<h2>{{ video['title'] }}</h2>
|
| 271 |
<p>{{ video['description'] }}</p>
|
| 272 |
<p>Загрузил: {{ video['uploader'] }} | {{ video['upload_date'] }}</p>
|
|
|
|
| 278 |
function toggleSidebar() {
|
| 279 |
document.getElementById('sidebar').classList.toggle('active');
|
| 280 |
}
|
| 281 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 282 |
+
const videos = document.querySelectorAll('.video-preview');
|
| 283 |
+
videos.forEach(video => {
|
| 284 |
+
video.addEventListener('loadedmetadata', function() {
|
| 285 |
+
const duration = video.duration;
|
| 286 |
+
const randomTime = Math.random() * duration;
|
| 287 |
+
video.currentTime = randomTime;
|
| 288 |
+
});
|
| 289 |
+
});
|
| 290 |
+
});
|
| 291 |
</script>
|
| 292 |
</body>
|
| 293 |
</html>
|
| 294 |
'''
|
| 295 |
+
return render_template_string(html, videos=videos, is_authenticated=is_authenticated, username=username, repo_id=REPO_ID)
|
| 296 |
|
| 297 |
# Страница отдельного видео
|
| 298 |
@app.route('/video/<video_id>')
|
|
|
|
| 401 |
.container { max-width: 800px; margin: 0 auto; padding-left: 220px; transition: padding-left 0.3s; }
|
| 402 |
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
|
| 403 |
.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
|
| 404 |
+
.video-preview { width: 100%; border-radius: 8px; height: 200px; object-fit: cover; }
|
| 405 |
.upload-btn, .delete-btn, .profile-link, .logout-btn { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }
|
| 406 |
.delete-btn { background: #ef4444; border: none; cursor: pointer; }
|
| 407 |
.profile-link { background: #10b981; }
|
|
|
|
| 414 |
.menu-btn { display: block; }
|
| 415 |
.video-grid { grid-template-columns: 1fr; }
|
| 416 |
.video-item { padding: 10px; }
|
| 417 |
+
.video-preview { height: 150px; }
|
| 418 |
.upload-btn, .delete-btn { font-size: 14px; padding: 8px; }
|
| 419 |
}
|
| 420 |
</style>
|
|
|
|
| 436 |
{% for video in user_videos %}
|
| 437 |
<div class="video-item">
|
| 438 |
<a href="{{ url_for('video_page', video_id=video['id']) }}">
|
| 439 |
+
<video class="video-preview" preload="metadata" muted>
|
| 440 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/videos/{{ video['filename'] }}" type="video/mp4">
|
| 441 |
+
</video>
|
| 442 |
<h3>{{ video['title'] }}</h3>
|
| 443 |
</a>
|
| 444 |
<p>{{ video['description'] }}</p>
|
|
|
|
| 458 |
function toggleSidebar() {
|
| 459 |
document.getElementById('sidebar').classList.toggle('active');
|
| 460 |
}
|
| 461 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 462 |
+
const videos = document.querySelectorAll('.video-preview');
|
| 463 |
+
videos.forEach(video => {
|
| 464 |
+
video.addEventListener('loadedmetadata', function() {
|
| 465 |
+
const duration = video.duration;
|
| 466 |
+
const randomTime = Math.random() * duration;
|
| 467 |
+
video.currentTime = randomTime;
|
| 468 |
+
});
|
| 469 |
+
});
|
| 470 |
+
});
|
| 471 |
</script>
|
| 472 |
</body>
|
| 473 |
</html>
|
| 474 |
'''
|
| 475 |
+
return render_template_string(html, username=username, user_videos=user_videos, repo_id=REPO_ID)
|
| 476 |
|
| 477 |
# Страница загрузки видео
|
| 478 |
@app.route('/upload', methods=['GET', 'POST'])
|