Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- base.html +71 -0
- my_profile.py +57 -0
base.html
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="ru">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>{% block title %}Emotion Analyzer{% endblock %}</title>
|
7 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
9 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
10 |
+
</head>
|
11 |
+
<body>
|
12 |
+
<div class="app-container">
|
13 |
+
<!-- Боковая панель -->
|
14 |
+
<div class="app-sidebar">
|
15 |
+
<div class="sidebar-header">
|
16 |
+
<h2><i class="fas fa-brain"></i> EmotionAnalyzer</h2>
|
17 |
+
</div>
|
18 |
+
|
19 |
+
<div class="sidebar-nav">
|
20 |
+
<a href="{{ url_for('index') }}" class="nav-item">
|
21 |
+
<i class="fas fa-home"></i> Главная
|
22 |
+
</a>
|
23 |
+
{% if current_user.is_authenticated %}
|
24 |
+
<a href="{{ url_for('profile.my_profile.py') }}" class="nav-item">
|
25 |
+
<i class="fas fa-user"></i> Профиль
|
26 |
+
</a>
|
27 |
+
{% endif %}
|
28 |
+
</div>
|
29 |
+
|
30 |
+
<div class="sidebar-footer">
|
31 |
+
{% if current_user.is_authenticated %}
|
32 |
+
<div class="user-info">
|
33 |
+
<i class="fas fa-user-circle"></i>
|
34 |
+
<span>{{ current_user.username }}</span>
|
35 |
+
</div>
|
36 |
+
<a href="{{ url_for('auth_bp.logout') }}" class="logout-btn">
|
37 |
+
<i class="fas fa-sign-out-alt"></i> Выйти
|
38 |
+
</a>
|
39 |
+
{% else %}
|
40 |
+
<div class="auth-links">
|
41 |
+
<a href="{{ url_for('auth_bp.login') }}" class="auth-link">Войти</a>
|
42 |
+
<a href="{{ url_for('auth_bp.register') }}" class="auth-link">Регистрация</a>
|
43 |
+
</div>
|
44 |
+
{% endif %}
|
45 |
+
</div>
|
46 |
+
</div>
|
47 |
+
|
48 |
+
<!-- Основное содержимое -->
|
49 |
+
<div class="app-main">
|
50 |
+
{% with messages = get_flashed_messages(with_categories=true) %}
|
51 |
+
{% if messages %}
|
52 |
+
<div class="flash-messages">
|
53 |
+
{% for category, message in messages %}
|
54 |
+
<div class="flash-message flash-{{ category }}">
|
55 |
+
{{ message }}
|
56 |
+
<button class="flash-close"><i class="fas fa-times"></i></button>
|
57 |
+
</div>
|
58 |
+
{% endfor %}
|
59 |
+
</div>
|
60 |
+
{% endif %}
|
61 |
+
{% endwith %}
|
62 |
+
|
63 |
+
{% block content %}{% endblock %}
|
64 |
+
</div>
|
65 |
+
</div>
|
66 |
+
|
67 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
68 |
+
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
69 |
+
{% block scripts %}{% endblock %}
|
70 |
+
</body>
|
71 |
+
</html>
|
my_profile.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from sqlalchemy import func
|
3 |
+
from flask import Blueprint, render_template
|
4 |
+
from flask_login import login_required, current_user
|
5 |
+
from datetime import datetime
|
6 |
+
|
7 |
+
from extensions import db
|
8 |
+
from models import AnalysisReport
|
9 |
+
|
10 |
+
profile_bp = Blueprint('profile', __name__)
|
11 |
+
|
12 |
+
@profile_bp.route('/profile')
|
13 |
+
@login_required
|
14 |
+
def profile():
|
15 |
+
# Получаем отчеты
|
16 |
+
reports = AnalysisReport.query.filter_by(user_id=current_user.id)\
|
17 |
+
.order_by(AnalysisReport.created_at.desc())\
|
18 |
+
.all()
|
19 |
+
|
20 |
+
# Преобразуем в список словарей с правильными датами
|
21 |
+
formatted_reports = []
|
22 |
+
for report in reports:
|
23 |
+
report_dict = {
|
24 |
+
'content': report.content,
|
25 |
+
'emotion': report.emotion,
|
26 |
+
'confidence': report.confidence,
|
27 |
+
'created_at': report.created_at.strftime('%Y-%m-%d %H:%M:%S') if report.created_at else None
|
28 |
+
}
|
29 |
+
formatted_reports.append(report_dict)
|
30 |
+
|
31 |
+
# Получаем статистику по эмоциям
|
32 |
+
emotion_stats = db.session.query(
|
33 |
+
AnalysisReport.emotion,
|
34 |
+
func.count(AnalysisReport.id).label('count')
|
35 |
+
).filter_by(user_id=current_user.id).group_by(AnalysisReport.emotion).all()
|
36 |
+
|
37 |
+
most_common_emotion = max(emotion_stats, key=lambda x: x.count).emotion if emotion_stats else None
|
38 |
+
total_reports = len(formatted_reports)
|
39 |
+
|
40 |
+
# Определяем emotion_map
|
41 |
+
emotion_map = {
|
42 |
+
'joy': '😊 Радость',
|
43 |
+
'neutral': '😐 Нейтрально',
|
44 |
+
'anger': '😠 Злость',
|
45 |
+
'sadness': '😢 Грусть',
|
46 |
+
'surprise': '😲 Удивление',
|
47 |
+
'happy': '😊 Радость',
|
48 |
+
'sad': '😢 Грусть',
|
49 |
+
'angry': '😠 Злость'
|
50 |
+
}
|
51 |
+
|
52 |
+
return render_template('profile.html',
|
53 |
+
reports=formatted_reports,
|
54 |
+
most_common_emotion=most_common_emotion,
|
55 |
+
total_reports=total_reports,
|
56 |
+
emotion_map=emotion_map,
|
57 |
+
datetime=datetime)
|