Spaces:
Zeuscloud
/
m
Sleeping

Eluza133 commited on
Commit
73c18df
·
verified ·
1 Parent(s): a1a50a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +233 -112
app.py CHANGED
@@ -216,7 +216,7 @@ BASE_STYLE = '''
216
  transform: scale(1.08);
217
  background: #e65b5b;
218
  }
219
- input, textarea {
220
  width: 100%;
221
  padding: 14px;
222
  margin: 15px 0;
@@ -227,11 +227,11 @@ BASE_STYLE = '''
227
  font-size: 1.1em;
228
  transition: var(--transition);
229
  }
230
- body.dark input, body.dark textarea {
231
  border: 2px solid rgba(255, 255, 255, 0.1);
232
  color: var(--text-dark);
233
  }
234
- input:focus, textarea:focus {
235
  outline: none;
236
  border-color: var(--primary);
237
  background: rgba(255, 245, 230, 0.2);
@@ -287,7 +287,7 @@ BASE_STYLE = '''
287
  top: 80px;
288
  right: 15px;
289
  }
290
- .btn, input, textarea {
291
  font-size: 1em;
292
  padding: 12px;
293
  }
@@ -606,44 +606,58 @@ def feed():
606
  }
607
  .post-grid {
608
  display: grid;
609
- grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
610
  gap: 30px;
611
  }
612
  .post-item {
613
  background: var(--card-bg-light);
614
  backdrop-filter: blur(20px);
615
- padding: 25px;
616
  border-radius: 20px;
617
  box-shadow: var(--shadow);
618
  transition: var(--transition);
619
  text-decoration: none;
620
  color: var(--text-light);
 
 
621
  }
622
  body.dark .post-item {
623
  background: var(--card-bg-dark);
624
  color: var(--text-dark);
625
  }
626
  .post-item:hover {
627
- transform: translateY(-15px);
 
628
  }
629
  .post-preview {
630
  width: 100%;
631
- height: 240px;
632
  object-fit: cover;
633
  border-radius: 15px;
634
- margin-bottom: 20px;
 
 
 
 
635
  }
636
  .post-item h2 {
637
- font-size: 1.5em;
638
- margin-bottom: 15px;
 
639
  }
640
  .post-item p {
641
- margin-bottom: 15px;
642
- font-size: 1.1em;
 
 
 
 
 
643
  }
644
  .stats {
645
- font-size: 1em;
646
  color: rgba(0, 0, 0, 0.6);
 
647
  }
648
  body.dark .stats {
649
  color: rgba(255, 255, 255, 0.6);
@@ -656,6 +670,16 @@ def feed():
656
  .username-link:hover {
657
  text-decoration: underline;
658
  }
 
 
 
 
 
 
 
 
 
 
659
  </style>
660
  </head>
661
  <body>
@@ -682,8 +706,11 @@ def feed():
682
  {% endif %}
683
  <h2>{{ post['title'] }}</h2>
684
  <p>{{ post['description'] }}</p>
685
- <p>Uploaded by: <a href="{{ url_for('user_profile', username=post['uploader']) }}" class="username-link">{{ post['uploader'] }}</a> | {{ post['upload_date'] }}</p>
686
- <p class="stats">Views: {{ post['views'] }} | Likes: {{ post['likes']|length }}</p>
 
 
 
687
  </a>
688
  {% endfor %}
689
  </div>
@@ -994,13 +1021,13 @@ def profile():
994
  }
995
  .post-grid {
996
  display: grid;
997
- grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
998
  gap: 30px;
999
  }
1000
  .post-item {
1001
  background: var(--card-bg-light);
1002
  backdrop-filter: blur(20px);
1003
- padding: 25px;
1004
  border-radius: 20px;
1005
  box-shadow: var(--shadow);
1006
  transition: var(--transition);
@@ -1009,18 +1036,24 @@ def profile():
1009
  background: var(--card-bg-dark);
1010
  }
1011
  .post-item:hover {
1012
- transform: translateY(-15px);
 
1013
  }
1014
  .post-preview {
1015
  width: 100%;
1016
- height: 240px;
1017
  object-fit: cover;
1018
  border-radius: 15px;
1019
- margin-bottom: 20px;
 
 
 
 
1020
  }
1021
  .post-item h3 {
1022
- font-size: 1.5em;
1023
- margin-bottom: 15px;
 
1024
  }
1025
  .delete-btn {
1026
  background: var(--secondary);
@@ -1209,13 +1242,13 @@ def user_profile(username):
1209
  }
1210
  .post-grid {
1211
  display: grid;
1212
- grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
1213
  gap: 30px;
1214
  }
1215
  .post-item {
1216
  background: var(--card-bg-light);
1217
  backdrop-filter: blur(20px);
1218
- padding: 25px;
1219
  border-radius: 20px;
1220
  box-shadow: var(--shadow);
1221
  transition: var(--transition);
@@ -1224,18 +1257,24 @@ def user_profile(username):
1224
  background: var(--card-bg-dark);
1225
  }
1226
  .post-item:hover {
1227
- transform: translateY(-15px);
 
1228
  }
1229
  .post-preview {
1230
  width: 100%;
1231
- height: 240px;
1232
  object-fit: cover;
1233
  border-radius: 15px;
1234
- margin-bottom: 20px;
 
 
 
 
1235
  }
1236
  .post-item h3 {
1237
- font-size: 1.5em;
1238
- margin-bottom: 15px;
 
1239
  }
1240
  .share-btn {
1241
  background: #ffa07a;
@@ -1507,49 +1546,57 @@ def chat():
1507
  is_authenticated = 'username' in session
1508
  username = session.get('username', None)
1509
  chat_messages = data['general_chat']
 
1510
 
1511
  if request.method == 'POST' and is_authenticated:
1512
- message = request.form.get('message')
1513
- file = request.files.get('file')
1514
- post_id = request.form.get('post_id')
 
1515
 
1516
- message_data = {
1517
- 'sender': username,
1518
- 'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
1519
- }
1520
-
1521
- if message:
1522
- message_data['text'] = message
1523
-
1524
- if file and file.filename:
1525
- filename = secure_filename(file.filename)
1526
- temp_path = os.path.join('uploads', filename)
1527
- os.makedirs('uploads', exist_ok=True)
1528
- file.save(temp_path)
1529
 
1530
- file_type = 'video' if filename.lower().endswith(('.mp4', '.mov', '.avi')) else 'photo'
1531
- api = HfApi()
1532
- file_path = f"chat_files/general/{filename}"
1533
- api.upload_file(
1534
- path_or_fileobj=temp_path,
1535
- path_in_repo=file_path,
1536
- repo_id=REPO_ID,
1537
- repo_type="dataset",
1538
- token=HF_TOKEN_WRITE,
1539
- commit_message=f"Uploaded chat file by {username}"
1540
- )
1541
- message_data['file'] = file_path
1542
- message_data['file_type'] = file_type
1543
- if os.path.exists(temp_path):
1544
- os.remove(temp_path)
1545
-
1546
- if post_id:
1547
- post = next((p for p in data['posts'] if p['id'] == post_id and p['uploader'] == username), None)
1548
- if post:
1549
- message_data['post_id'] = post_id
 
 
 
 
 
 
 
 
 
 
 
 
 
1550
 
1551
- if 'text' in message_data or 'file' in message_data or 'post_id' in message_data:
1552
- data['general_chat'].append(message_data)
 
1553
  save_data(data)
1554
 
1555
  return redirect(url_for('chat'))
@@ -1569,7 +1616,7 @@ def chat():
1569
  max-width: 950px;
1570
  background: var(--card-bg-light);
1571
  backdrop-filter: blur(20px);
1572
- padding: 50px;
1573
  border-radius: 25px;
1574
  box-shadow: var(--shadow);
1575
  }
@@ -1579,20 +1626,79 @@ def chat():
1579
  h1 {
1580
  font-size: 2.5em;
1581
  font-weight: 700;
1582
- margin-bottom: 30px;
1583
  background: linear-gradient(45deg, var(--primary), var(--secondary));
1584
  -webkit-background-clip: text;
1585
  color: transparent;
1586
  }
 
 
 
 
 
 
 
 
1587
  .message {
 
 
1588
  padding: 15px;
1589
- background: var(--glass-bg);
1590
  border-radius: 15px;
1591
  margin-bottom: 15px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1592
  }
1593
  .message img, .message video {
1594
- max-width: 300px;
1595
- max-height: 300px;
1596
  border-radius: 10px;
1597
  margin-top: 10px;
1598
  }
@@ -1606,17 +1712,6 @@ def chat():
1606
  .message-form {
1607
  margin-top: 20px;
1608
  }
1609
- .post-select {
1610
- margin: 15px 0;
1611
- padding: 14px;
1612
- width: 100%;
1613
- border-radius: 15px;
1614
- background: var(--glass-bg);
1615
- color: var(--text-light);
1616
- }
1617
- body.dark .post-select {
1618
- color: var(--text-dark);
1619
- }
1620
  </style>
1621
  </head>
1622
  <body>
@@ -1625,29 +1720,46 @@ def chat():
1625
  <button class="theme-toggle" onclick="toggleTheme()">🌙</button>
1626
  <div class="container">
1627
  <h1>General Chat</h1>
1628
- <div class="messages">
1629
  {% for message in chat_messages %}
1630
  <div class="message">
1631
- <strong>{{ message['sender'] }}</strong> ({{ message['time'] }}):
1632
- {% if 'text' in message %}
1633
- <p>{{ message['text'] }}</p>
 
 
1634
  {% endif %}
1635
- {% if 'file' in message %}
1636
- {% if message['file_type'] == 'video' %}
1637
- <video controls>
1638
- <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" type="video/mp4">
1639
- </video>
1640
- {% else %}
1641
- <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" alt="Chat file" onclick="openModal(this.src)">
 
 
 
 
 
 
1642
  {% endif %}
1643
- {% endif %}
1644
- {% if 'post_id' in message %}
1645
- {% with post = posts|selectattr('id', 'equalto', message['post_id'])|first %}
1646
- {% if post %}
1647
- <p>Shared post: <a href="{{ url_for('post_page', post_id=message['post_id']) }}">{{ post['title'] }}</a></p>
 
 
1648
  {% endif %}
1649
- {% endwith %}
1650
- {% endif %}
 
 
 
 
 
 
 
1651
  </div>
1652
  {% endfor %}
1653
  </div>
@@ -1661,7 +1773,7 @@ def chat():
1661
  <option value="{{ post['id'] }}">{{ post['title'] }}</option>
1662
  {% endfor %}
1663
  </select>
1664
- <button type="submit" class="btn">Send</button>
1665
  </form>
1666
  {% else %}
1667
  <p style="margin-top: 20px;"><a href="{{ url_for('login') }}">Login</a> to send messages.</p>
@@ -1691,6 +1803,8 @@ def chat():
1691
  }
1692
  window.onload = () => {
1693
  if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
 
 
1694
  };
1695
  </script>
1696
  </body>
@@ -1699,11 +1813,13 @@ def chat():
1699
  user_posts = [p for p in data['posts'] if p['uploader'] == username] if is_authenticated else []
1700
  return render_template_string(html,
1701
  chat_messages=chat_messages,
1702
- username=username,
1703
  is_authenticated=is_authenticated,
 
1704
  repo_id=REPO_ID,
1705
  posts=data['posts'],
1706
- user_posts=user_posts)
 
1707
 
1708
  # Admin panel
1709
  @app.route('/admhosto', methods=['GET', 'POST'])
@@ -1744,7 +1860,7 @@ def admin_panel():
1744
  color: transparent;
1745
  }
1746
  .search-container {
1747
- max-width: 600px;
1748
  margin: 0 auto 40px;
1749
  position: relative;
1750
  }
@@ -1773,13 +1889,13 @@ def admin_panel():
1773
  }
1774
  .post-grid {
1775
  display: grid;
1776
- grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
1777
  gap: 30px;
1778
  }
1779
  .post-item {
1780
  background: var(--card-bg-light);
1781
  backdrop-filter: blur(20px);
1782
- padding: 25px;
1783
  border-radius: 20px;
1784
  box-shadow: var(--shadow);
1785
  transition: var(--transition);
@@ -1788,17 +1904,22 @@ def admin_panel():
1788
  background: var(--card-bg-dark);
1789
  }
1790
  .post-item:hover {
1791
- transform: translateY(-15px);
 
1792
  }
1793
  .post-preview {
1794
  width: 100%;
1795
- height: 240px;
1796
  object-fit: cover;
1797
  border-radius: 15px;
1798
- margin-bottom: 20px;
 
 
 
 
1799
  }
1800
  .post-item h2 {
1801
- font-size: 1.5em;
1802
  margin-bottom: 15px;
1803
  }
1804
  .post-item p {
 
216
  transform: scale(1.08);
217
  background: #e65b5b;
218
  }
219
+ input, textarea, select {
220
  width: 100%;
221
  padding: 14px;
222
  margin: 15px 0;
 
227
  font-size: 1.1em;
228
  transition: var(--transition);
229
  }
230
+ body.dark input, body.dark textarea, body.dark select {
231
  border: 2px solid rgba(255, 255, 255, 0.1);
232
  color: var(--text-dark);
233
  }
234
+ input:focus, textarea:focus, select:focus {
235
  outline: none;
236
  border-color: var(--primary);
237
  background: rgba(255, 245, 230, 0.2);
 
287
  top: 80px;
288
  right: 15px;
289
  }
290
+ .btn, input, textarea, select {
291
  font-size: 1em;
292
  padding: 12px;
293
  }
 
606
  }
607
  .post-grid {
608
  display: grid;
609
+ grid-template-columns: repeat(2, 1fr);
610
  gap: 30px;
611
  }
612
  .post-item {
613
  background: var(--card-bg-light);
614
  backdrop-filter: blur(20px);
615
+ padding: 20px;
616
  border-radius: 20px;
617
  box-shadow: var(--shadow);
618
  transition: var(--transition);
619
  text-decoration: none;
620
  color: var(--text-light);
621
+ position: relative;
622
+ overflow: hidden;
623
  }
624
  body.dark .post-item {
625
  background: var(--card-bg-dark);
626
  color: var(--text-dark);
627
  }
628
  .post-item:hover {
629
+ transform: translateY(-10px);
630
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
631
  }
632
  .post-preview {
633
  width: 100%;
634
+ height: 300px;
635
  object-fit: cover;
636
  border-radius: 15px;
637
+ margin-bottom: 15px;
638
+ transition: var(--transition);
639
+ }
640
+ .post-item:hover .post-preview {
641
+ filter: brightness(1.1);
642
  }
643
  .post-item h2 {
644
+ font-size: 1.6em;
645
+ margin-bottom: 10px;
646
+ font-weight: 600;
647
  }
648
  .post-item p {
649
+ font-size: 1em;
650
+ margin-bottom: 10px;
651
+ display: -webkit-box;
652
+ -webkit-line-clamp: 3;
653
+ -webkit-box-orient: vertical;
654
+ overflow: hidden;
655
+ text-overflow: ellipsis;
656
  }
657
  .stats {
658
+ font-size: 0.9em;
659
  color: rgba(0, 0, 0, 0.6);
660
+ margin-top: 10px;
661
  }
662
  body.dark .stats {
663
  color: rgba(255, 255, 255, 0.6);
 
670
  .username-link:hover {
671
  text-decoration: underline;
672
  }
673
+ .post-meta {
674
+ display: flex;
675
+ justify-content: space-between;
676
+ align-items: center;
677
+ font-size: 0.9em;
678
+ color: rgba(0, 0, 0, 0.7);
679
+ }
680
+ body.dark .post-meta {
681
+ color: rgba(255, 255, 255, 0.7);
682
+ }
683
  </style>
684
  </head>
685
  <body>
 
706
  {% endif %}
707
  <h2>{{ post['title'] }}</h2>
708
  <p>{{ post['description'] }}</p>
709
+ <div class="post-meta">
710
+ <span>By <a href="{{ url_for('user_profile', username=post['uploader']) }}" class="username-link">{{ post['uploader'] }}</a></span>
711
+ <span>{{ post['upload_date'] }}</span>
712
+ </div>
713
+ <div class="stats">Views: {{ post['views'] }} | Likes: {{ post['likes']|length }}</div>
714
  </a>
715
  {% endfor %}
716
  </div>
 
1021
  }
1022
  .post-grid {
1023
  display: grid;
1024
+ grid-template-columns: repeat(2, 1fr);
1025
  gap: 30px;
1026
  }
1027
  .post-item {
1028
  background: var(--card-bg-light);
1029
  backdrop-filter: blur(20px);
1030
+ padding: 20px;
1031
  border-radius: 20px;
1032
  box-shadow: var(--shadow);
1033
  transition: var(--transition);
 
1036
  background: var(--card-bg-dark);
1037
  }
1038
  .post-item:hover {
1039
+ transform: translateY(-10px);
1040
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
1041
  }
1042
  .post-preview {
1043
  width: 100%;
1044
+ height: 300px;
1045
  object-fit: cover;
1046
  border-radius: 15px;
1047
+ margin-bottom: 15px;
1048
+ transition: var(--transition);
1049
+ }
1050
+ .post-item:hover .post-preview {
1051
+ filter: brightness(1.1);
1052
  }
1053
  .post-item h3 {
1054
+ font-size: 1.6em;
1055
+ margin-bottom: 10px;
1056
+ font-weight: 600;
1057
  }
1058
  .delete-btn {
1059
  background: var(--secondary);
 
1242
  }
1243
  .post-grid {
1244
  display: grid;
1245
+ grid-template-columns: repeat(2, 1fr);
1246
  gap: 30px;
1247
  }
1248
  .post-item {
1249
  background: var(--card-bg-light);
1250
  backdrop-filter: blur(20px);
1251
+ padding: 20px;
1252
  border-radius: 20px;
1253
  box-shadow: var(--shadow);
1254
  transition: var(--transition);
 
1257
  background: var(--card-bg-dark);
1258
  }
1259
  .post-item:hover {
1260
+ transform: translateY(-10px);
1261
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
1262
  }
1263
  .post-preview {
1264
  width: 100%;
1265
+ height: 300px;
1266
  object-fit: cover;
1267
  border-radius: 15px;
1268
+ margin-bottom: 15px;
1269
+ transition: var(--transition);
1270
+ }
1271
+ .post-item:hover .post-preview {
1272
+ filter: brightness(1.1);
1273
  }
1274
  .post-item h3 {
1275
+ font-size: 1.6em;
1276
+ margin-bottom: 10px;
1277
+ font-weight: 600;
1278
  }
1279
  .share-btn {
1280
  background: #ffa07a;
 
1546
  is_authenticated = 'username' in session
1547
  username = session.get('username', None)
1548
  chat_messages = data['general_chat']
1549
+ is_admin = username == "admin" # Условный админ
1550
 
1551
  if request.method == 'POST' and is_authenticated:
1552
+ if 'send_message' in request.form:
1553
+ message = request.form.get('message')
1554
+ file = request.files.get('file')
1555
+ post_id = request.form.get('post_id')
1556
 
1557
+ message_data = {
1558
+ 'id': len(chat_messages) + 1, # Уникальный ID для сообщения
1559
+ 'sender': username,
1560
+ 'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
1561
+ }
 
 
 
 
 
 
 
 
1562
 
1563
+ if message:
1564
+ message_data['text'] = message
1565
+
1566
+ if file and file.filename:
1567
+ filename = secure_filename(file.filename)
1568
+ temp_path = os.path.join('uploads', filename)
1569
+ os.makedirs('uploads', exist_ok=True)
1570
+ file.save(temp_path)
1571
+
1572
+ file_type = 'video' if filename.lower().endswith(('.mp4', '.mov', '.avi')) else 'photo'
1573
+ api = HfApi()
1574
+ file_path = f"chat_files/general/{filename}"
1575
+ api.upload_file(
1576
+ path_or_fileobj=temp_path,
1577
+ path_in_repo=file_path,
1578
+ repo_id=REPO_ID,
1579
+ repo_type="dataset",
1580
+ token=HF_TOKEN_WRITE,
1581
+ commit_message=f"Uploaded chat file by {username}"
1582
+ )
1583
+ message_data['file'] = file_path
1584
+ message_data['file_type'] = file_type
1585
+ if os.path.exists(temp_path):
1586
+ os.remove(temp_path)
1587
+
1588
+ if post_id:
1589
+ post = next((p for p in data['posts'] if p['id'] == post_id and p['uploader'] == username), None)
1590
+ if post:
1591
+ message_data['post_id'] = post_id
1592
+
1593
+ if 'text' in message_data or 'file' in message_data or 'post_id' in message_data:
1594
+ data['general_chat'].append(message_data)
1595
+ save_data(data)
1596
 
1597
+ elif 'kick_message' in request.form and is_admin:
1598
+ message_id = int(request.form.get('message_id'))
1599
+ data['general_chat'] = [msg for msg in data['general_chat'] if msg['id'] != message_id]
1600
  save_data(data)
1601
 
1602
  return redirect(url_for('chat'))
 
1616
  max-width: 950px;
1617
  background: var(--card-bg-light);
1618
  backdrop-filter: blur(20px);
1619
+ padding: 30px;
1620
  border-radius: 25px;
1621
  box-shadow: var(--shadow);
1622
  }
 
1626
  h1 {
1627
  font-size: 2.5em;
1628
  font-weight: 700;
1629
+ margin-bottom: 20px;
1630
  background: linear-gradient(45deg, var(--primary), var(--secondary));
1631
  -webkit-background-clip: text;
1632
  color: transparent;
1633
  }
1634
+ .chat-box {
1635
+ max-height: 500px;
1636
+ overflow-y: auto;
1637
+ margin-bottom: 20px;
1638
+ padding: 10px;
1639
+ border-radius: 15px;
1640
+ background: var(--glass-bg);
1641
+ }
1642
  .message {
1643
+ display: flex;
1644
+ align-items: flex-start;
1645
  padding: 15px;
1646
+ background: var(--card-bg-light);
1647
  border-radius: 15px;
1648
  margin-bottom: 15px;
1649
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
1650
+ transition: var(--transition);
1651
+ }
1652
+ body.dark .message {
1653
+ background: var(--card-bg-dark);
1654
+ }
1655
+ .message:hover {
1656
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
1657
+ }
1658
+ .message-avatar {
1659
+ width: 40px;
1660
+ height: 40px;
1661
+ border-radius: 50%;
1662
+ margin-right: 15px;
1663
+ object-fit: cover;
1664
+ }
1665
+ .message-content {
1666
+ flex: 1;
1667
+ }
1668
+ .message-header {
1669
+ display: flex;
1670
+ align-items: center;
1671
+ gap: 10px;
1672
+ margin-bottom: 5px;
1673
+ }
1674
+ .message-sender {
1675
+ font-weight: 600;
1676
+ color: var(--primary);
1677
+ text-decoration: none;
1678
+ }
1679
+ .message-sender:hover {
1680
+ text-decoration: underline;
1681
+ }
1682
+ .message-time {
1683
+ font-size: 0.9em;
1684
+ color: rgba(0, 0, 0, 0.6);
1685
+ }
1686
+ body.dark .message-time {
1687
+ color: rgba(255, 255, 255, 0.6);
1688
+ }
1689
+ .kick-btn {
1690
+ background: #ff4444;
1691
+ padding: 5px 10px;
1692
+ font-size: 0.9em;
1693
+ border-radius: 10px;
1694
+ }
1695
+ .kick-btn:hover {
1696
+ background: #cc3333;
1697
+ transform: scale(1.05);
1698
  }
1699
  .message img, .message video {
1700
+ max-width: 250px;
1701
+ max-height: 250px;
1702
  border-radius: 10px;
1703
  margin-top: 10px;
1704
  }
 
1712
  .message-form {
1713
  margin-top: 20px;
1714
  }
 
 
 
 
 
 
 
 
 
 
 
1715
  </style>
1716
  </head>
1717
  <body>
 
1720
  <button class="theme-toggle" onclick="toggleTheme()">🌙</button>
1721
  <div class="container">
1722
  <h1>General Chat</h1>
1723
+ <div class="chat-box">
1724
  {% for message in chat_messages %}
1725
  <div class="message">
1726
+ {% set sender_data = users[message['sender']] %}
1727
+ {% if sender_data['avatar'] %}
1728
+ <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ sender_data['avatar'] }}" alt="{{ message['sender'] }}" class="message-avatar">
1729
+ {% else %}
1730
+ <div class="message-avatar" style="background: var(--primary);"></div>
1731
  {% endif %}
1732
+ <div class="message-content">
1733
+ <div class="message-header">
1734
+ <a href="{{ url_for('user_profile', username=message['sender']) }}" class="message-sender">{{ message['sender'] }}</a>
1735
+ <span class="message-time">{{ message['time'] }}</span>
1736
+ {% if is_admin %}
1737
+ <form method="POST" style="display: inline;">
1738
+ <input type="hidden" name="message_id" value="{{ message['id'] }}">
1739
+ <button type="submit" name="kick_message" class="btn kick-btn">Kick</button>
1740
+ </form>
1741
+ {% endif %}
1742
+ </div>
1743
+ {% if 'text' in message %}
1744
+ <p>{{ message['text'] }}</p>
1745
  {% endif %}
1746
+ {% if 'file' in message %}
1747
+ {% if message['file_type'] == 'video' %}
1748
+ <video controls>
1749
+ <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" type="video/mp4">
1750
+ </video>
1751
+ {% else %}
1752
+ <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" alt="Chat file" onclick="openModal(this.src)">
1753
  {% endif %}
1754
+ {% endif %}
1755
+ {% if 'post_id' in message %}
1756
+ {% with post = posts|selectattr('id', 'equalto', message['post_id'])|first %}
1757
+ {% if post %}
1758
+ <p>Shared: <a href="{{ url_for('post_page', post_id=message['post_id']) }}">{{ post['title'] }}</a></p>
1759
+ {% endif %}
1760
+ {% endwith %}
1761
+ {% endif %}
1762
+ </div>
1763
  </div>
1764
  {% endfor %}
1765
  </div>
 
1773
  <option value="{{ post['id'] }}">{{ post['title'] }}</option>
1774
  {% endfor %}
1775
  </select>
1776
+ <button type="submit" name="send_message" class="btn">Send</button>
1777
  </form>
1778
  {% else %}
1779
  <p style="margin-top: 20px;"><a href="{{ url_for('login') }}">Login</a> to send messages.</p>
 
1803
  }
1804
  window.onload = () => {
1805
  if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
1806
+ const chatBox = document.querySelector('.chat-box');
1807
+ chatBox.scrollTop = chatBox.scrollHeight;
1808
  };
1809
  </script>
1810
  </body>
 
1813
  user_posts = [p for p in data['posts'] if p['uploader'] == username] if is_authenticated else []
1814
  return render_template_string(html,
1815
  chat_messages=chat_messages,
1816
+ username=username,
1817
  is_authenticated=is_authenticated,
1818
+ is_admin=is_admin,
1819
  repo_id=REPO_ID,
1820
  posts=data['posts'],
1821
+ user_posts=user_posts,
1822
+ users=data['users'])
1823
 
1824
  # Admin panel
1825
  @app.route('/admhosto', methods=['GET', 'POST'])
 
1860
  color: transparent;
1861
  }
1862
  .search-container {
1863
+ max-width: 600px;
1864
  margin: 0 auto 40px;
1865
  position: relative;
1866
  }
 
1889
  }
1890
  .post-grid {
1891
  display: grid;
1892
+ grid-template-columns: repeat(2, 1fr);
1893
  gap: 30px;
1894
  }
1895
  .post-item {
1896
  background: var(--card-bg-light);
1897
  backdrop-filter: blur(20px);
1898
+ padding: 20px;
1899
  border-radius: 20px;
1900
  box-shadow: var(--shadow);
1901
  transition: var(--transition);
 
1904
  background: var(--card-bg-dark);
1905
  }
1906
  .post-item:hover {
1907
+ transform: translateY(-10px);
1908
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
1909
  }
1910
  .post-preview {
1911
  width: 100%;
1912
+ height: 300px;
1913
  object-fit: cover;
1914
  border-radius: 15px;
1915
+ margin-bottom: 15px;
1916
+ transition: var(--transition);
1917
+ }
1918
+ .post-item:hover .post-preview {
1919
+ filter: brightness(1.1);
1920
  }
1921
  .post-item h2 {
1922
+ font-size: 1.6em;
1923
  margin-bottom: 15px;
1924
  }
1925
  .post-item p {