vioott commited on
Commit
1387ef8
·
1 Parent(s): 48d9602

feat(start): allow toggling between new profile creation and existing profiles list

Browse files
Files changed (3) hide show
  1. app.py +3 -4
  2. static/style.css +18 -2
  3. templates/start.html +43 -11
app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import re
3
  import google.generativeai as genai
4
  from flask import Flask, redirect, render_template, request
5
- from user_data import get_user_history
6
  from logs import save_log
7
 
8
  app = Flask(__name__)
@@ -42,7 +42,7 @@ def genai_configuration():
42
  test_model.start_chat().send_message("ping")
43
 
44
  return
45
-
46
  except Exception:
47
  print("❌ Todas as chaves falharam.")
48
 
@@ -87,7 +87,6 @@ def inicio():
87
  preferences = request.form.getlist('preferences')
88
 
89
  # Simula criação de novo ID
90
- from user_data import user_histories
91
  new_id = max(user_histories.keys()) + 1
92
  user_histories[new_id] = {
93
  'fiction': 0,
@@ -100,7 +99,7 @@ def inicio():
100
 
101
  return redirect(f'/chat/{new_id}')
102
 
103
- return render_template('start.html')
104
 
105
 
106
  @app.route('/perfil/<int:user_id>', methods=['GET', 'POST'])
 
2
  import re
3
  import google.generativeai as genai
4
  from flask import Flask, redirect, render_template, request
5
+ from user_data import get_user_history, user_histories
6
  from logs import save_log
7
 
8
  app = Flask(__name__)
 
42
  test_model.start_chat().send_message("ping")
43
 
44
  return
45
+
46
  except Exception:
47
  print("❌ Todas as chaves falharam.")
48
 
 
87
  preferences = request.form.getlist('preferences')
88
 
89
  # Simula criação de novo ID
 
90
  new_id = max(user_histories.keys()) + 1
91
  user_histories[new_id] = {
92
  'fiction': 0,
 
99
 
100
  return redirect(f'/chat/{new_id}')
101
 
102
+ return render_template('start.html', profiles=user_histories)
103
 
104
 
105
  @app.route('/perfil/<int:user_id>', methods=['GET', 'POST'])
static/style.css CHANGED
@@ -20,7 +20,7 @@ form {
20
  h1 {
21
  text-align: left;
22
  color: black;
23
- margin-bottom: 30px;
24
  }
25
 
26
  label {
@@ -86,9 +86,25 @@ button:hover {
86
 
87
  .chat-container:has(.chat-box):not(:has(.response-box)) .chat-box,
88
  .chat-container:has(.response-box):not(:has(.chat-box)) .response-box {
89
- width: 100%;
90
  }
91
 
92
  .resposta-formatada {
93
  line-height: 1.6;
94
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  h1 {
21
  text-align: left;
22
  color: black;
23
+ margin-bottom: 10px;
24
  }
25
 
26
  label {
 
86
 
87
  .chat-container:has(.chat-box):not(:has(.response-box)) .chat-box,
88
  .chat-container:has(.response-box):not(:has(.chat-box)) .response-box {
89
+ width: 100%;
90
  }
91
 
92
  .resposta-formatada {
93
  line-height: 1.6;
94
  }
95
+
96
+ .hidden {
97
+ display: none;
98
+ }
99
+
100
+ .small-link {
101
+ font-size: 0.9em;
102
+ text-align: left;
103
+ margin-bottom: 30px;
104
+ }
105
+
106
+ .small-link a {
107
+ text-decoration: underline;
108
+ color: blue;
109
+ cursor: pointer;
110
+ }
templates/start.html CHANGED
@@ -3,25 +3,57 @@
3
  <head>
4
  <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
5
  <title>Bem-vindo!</title>
 
 
 
 
 
 
 
 
 
 
6
  </head>
7
  <body>
8
 
9
  <form method="POST">
10
  <h1>Vamos criar seu perfil?</h1>
11
- <label for="name">Seu nome:</label>
12
- <input type="text" id="name" name="name" required><br><br>
13
 
14
- <p>Quais gêneros de livros você gosta?</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- {% for genre in ['ficção', 'não-ficção', 'ciência', 'fantasia'] %}
17
- <label class="genre-label" for="{{ genre }}">
18
- <input type="checkbox" id="{{ genre }}" name="preferences" value="{{ genre }}">
19
- {{ genre.title() }}
20
- </label>
21
- {% endfor %}
22
 
23
- <br>
24
- <button type="submit">Começar</button>
25
  </form>
26
 
27
  </body>
 
3
  <head>
4
  <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
5
  <title>Bem-vindo!</title>
6
+
7
+ <script>
8
+ function mostrarPerfis() {
9
+ document.getElementById('existing-profiles').classList.remove('hidden');
10
+ document.getElementById('formulario-perfil').classList.add('hidden');
11
+ document.getElementById('link-ja-tenho').classList.add('hidden');
12
+ document.getElementById('link-criar').classList.remove('hidden');
13
+ }
14
+ </script>
15
+
16
  </head>
17
  <body>
18
 
19
  <form method="POST">
20
  <h1>Vamos criar seu perfil?</h1>
 
 
21
 
22
+ <div class="small-link" id="link-ja-tenho">
23
+ <a href="#" onclick="mostrarPerfis(); return false;">Já tenho perfil</a>
24
+ </div>
25
+
26
+ <div class="small-link hidden" id="link-criar">
27
+ <a href="/">Criar perfil</a>
28
+ </div>
29
+
30
+ <div id="existing-profiles" class="hidden">
31
+ <h2>Perfis existentes</h2>
32
+ <ul>
33
+ {% for id, data in profiles.items() %}
34
+ <li><a href="/perfil/{{ id }}">{{ data.name or "Usuário " ~ id }}</a></li>
35
+ {% endfor %}
36
+ </ul>
37
+ </div>
38
+
39
+ <div id="formulario-perfil">
40
+ <label for="name">Seu nome:</label>
41
+ <input type="text" id="name" name="name" required><br><br>
42
+
43
+ <p>Quais gêneros de livros você gosta?</p>
44
+
45
+ {% for genre in ['ficção', 'não-ficção', 'ciência', 'fantasia'] %}
46
+ <label class="genre-label" for="{{ genre }}">
47
+ <input type="checkbox" id="{{ genre }}" name="preferences" value="{{ genre }}">
48
+ {{ genre.title() }}
49
+ </label>
50
+ {% endfor %}
51
+
52
+ <br>
53
+ <button type="submit">Começar</button>
54
 
55
+ </div>
 
 
 
 
 
56
 
 
 
57
  </form>
58
 
59
  </body>