AIdeaText commited on
Commit
7284cbd
·
verified ·
2 Parent(s): 7d60ac9 303420a

Merge branch #AIdeaText/test' into 'AIdeaText/test2'

Browse files
app.py CHANGED
@@ -25,7 +25,8 @@ from modules.ui.ui import (
25
  display_semantic_analysis_interface,
26
  display_discourse_analysis_interface,
27
  display_student_progress,
28
- display_chatbot_interface
 
29
  )
30
  from modules.utils.spacy_utils import load_spacy_models
31
  import logging
@@ -39,7 +40,6 @@ st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
39
  st.cache_data.clear()
40
  st.cache_resource.clear()
41
 
42
-
43
  # Cargar los modelos de spaCy una vez al inicio de la aplicación
44
  print("Cargando modelos")
45
  @st.cache_resource
@@ -115,7 +115,7 @@ def logged_in_interface():
115
  # Añadir una línea divisoria
116
  st.markdown("---")
117
 
118
- tab1, tab2, tab3, tab4, tab5 = st.tabs(["Análisis morfosintáctico", "Análisis semántico", "Análisis del discurso", "Chat con Llama2", "Mi Progreso"])
119
 
120
  with tab1:
121
  display_morphosyntax_analysis_interface(nlp_models, lang_code)
@@ -127,6 +127,8 @@ def logged_in_interface():
127
  display_chatbot_interface(lang_code)
128
  with tab5:
129
  display_student_progress(st.session_state.username, lang_code)
 
 
130
 
131
  ###################################################################################################################
132
  if __name__ == "__main__":
 
25
  display_semantic_analysis_interface,
26
  display_discourse_analysis_interface,
27
  display_student_progress,
28
+ display_chatbot_interface,
29
+ display_feedback_form
30
  )
31
  from modules.utils.spacy_utils import load_spacy_models
32
  import logging
 
40
  st.cache_data.clear()
41
  st.cache_resource.clear()
42
 
 
43
  # Cargar los modelos de spaCy una vez al inicio de la aplicación
44
  print("Cargando modelos")
45
  @st.cache_resource
 
115
  # Añadir una línea divisoria
116
  st.markdown("---")
117
 
118
+ tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Análisis morfosintáctico", "Análisis semántico", "Análisis del discurso", "Chat con Llama2", "Mi Progreso", "Formulario de Retroalimentación"])
119
 
120
  with tab1:
121
  display_morphosyntax_analysis_interface(nlp_models, lang_code)
 
127
  display_chatbot_interface(lang_code)
128
  with tab5:
129
  display_student_progress(st.session_state.username, lang_code)
130
+ with tab6:
131
+ display_feedback_form(lang_code)
132
 
133
  ###################################################################################################################
134
  if __name__ == "__main__":
modules/__init__.py CHANGED
@@ -17,7 +17,8 @@ def load_database_function():
17
  store_discourse_analysis_result,
18
  store_chat_history,
19
  create_admin_user,
20
- create_student_user
 
21
  )
22
  return {
23
  'initialize_mongodb_connection': initialize_mongodb_connection,
@@ -28,7 +29,8 @@ def load_database_function():
28
  'store_discourse_analysis_result': store_discourse_analysis_result,
29
  'store_chat_history': store_chat_history,
30
  'create_admin_user': create_admin_user,
31
- 'create_student_user': create_student_user
 
32
  }
33
 
34
  def load_ui_functions():
@@ -42,7 +44,8 @@ def load_ui_functions():
42
  display_morphosyntax_analysis_interface,
43
  display_semantic_analysis_interface,
44
  display_discourse_analysis_interface,
45
- display_chatbot_interface
 
46
  )
47
  return {
48
  'main': main,
@@ -54,7 +57,14 @@ def load_ui_functions():
54
  'display_morphosyntax_analysis_interface': display_morphosyntax_analysis_interface,
55
  'display_semantic_analysis_interface': display_semantic_analysis_interface,
56
  'display_discourse_analysis_interface': display_discourse_analysis_interface,
57
- 'display_chatbot_interface': display_chatbot_interface
 
 
 
 
 
 
 
58
  }
59
 
60
  def load_admin_functions():
@@ -131,4 +141,5 @@ def load_all_functions():
131
  **discourse_analysis_text_functions(),
132
  **spacy_utils_functions(),
133
  **chatbot_functions()
 
134
  }
 
17
  store_discourse_analysis_result,
18
  store_chat_history,
19
  create_admin_user,
20
+ create_student_user,
21
+ store_user_feedback
22
  )
23
  return {
24
  'initialize_mongodb_connection': initialize_mongodb_connection,
 
29
  'store_discourse_analysis_result': store_discourse_analysis_result,
30
  'store_chat_history': store_chat_history,
31
  'create_admin_user': create_admin_user,
32
+ 'create_student_user': create_student_user,
33
+ 'store_user_feedback': store_user_feedback,
34
  }
35
 
36
  def load_ui_functions():
 
44
  display_morphosyntax_analysis_interface,
45
  display_semantic_analysis_interface,
46
  display_discourse_analysis_interface,
47
+ display_chatbot_interface,
48
+ display_feedback_form
49
  )
50
  return {
51
  'main': main,
 
57
  'display_morphosyntax_analysis_interface': display_morphosyntax_analysis_interface,
58
  'display_semantic_analysis_interface': display_semantic_analysis_interface,
59
  'display_discourse_analysis_interface': display_discourse_analysis_interface,
60
+ 'display_chatbot_interface': display_chatbot_interface,
61
+ 'display_feedback_form': display_feedback_form
62
+ }
63
+
64
+ def load_email_functions():
65
+ from modules.email.email import send_email_notification
66
+ return {
67
+ 'send_email_notification': send_email_notification
68
  }
69
 
70
  def load_admin_functions():
 
141
  **discourse_analysis_text_functions(),
142
  **spacy_utils_functions(),
143
  **chatbot_functions()
144
+ **load_email_functions()
145
  }
modules/database/database.py CHANGED
@@ -22,6 +22,7 @@ application_requests_container = None
22
  cosmos_client = None
23
  user_database = None
24
  user_container = None
 
25
 
26
  # Variables globales para Cosmos DB MongoDB API
27
  mongo_client = None
@@ -55,7 +56,7 @@ def initialize_database_connections():
55
 
56
  #####################################################################################33
57
  def initialize_cosmos_sql_connection():
58
- global cosmos_client, user_database, user_container, application_requests_container
59
  logger.info("Initializing Cosmos DB SQL API connection")
60
  try:
61
  cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
@@ -71,9 +72,11 @@ def initialize_cosmos_sql_connection():
71
  user_database = cosmos_client.get_database_client("user_database")
72
  user_container = user_database.get_container_client("users")
73
  application_requests_container = user_database.get_container_client("application_requests")
 
74
 
75
  logger.info(f"user_container initialized: {user_container is not None}")
76
  logger.info(f"application_requests_container initialized: {application_requests_container is not None}")
 
77
 
78
  logger.info("Conexión a Cosmos DB SQL API exitosa")
79
  return True
@@ -192,6 +195,33 @@ def store_application_request(name, email, institution, role, reason):
192
  return False
193
 
194
  #######################################################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  def store_morphosyntax_result(username, text, repeated_words, arc_diagrams, pos_analysis, morphological_analysis, sentence_structure):
196
  if analysis_collection is None:
197
  logger.error("La conexión a MongoDB no está inicializada")
 
22
  cosmos_client = None
23
  user_database = None
24
  user_container = None
25
+ user_feedback_container = None
26
 
27
  # Variables globales para Cosmos DB MongoDB API
28
  mongo_client = None
 
56
 
57
  #####################################################################################33
58
  def initialize_cosmos_sql_connection():
59
+ global cosmos_client, user_database, user_container, application_requests_container, user_feedback_container
60
  logger.info("Initializing Cosmos DB SQL API connection")
61
  try:
62
  cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
 
72
  user_database = cosmos_client.get_database_client("user_database")
73
  user_container = user_database.get_container_client("users")
74
  application_requests_container = user_database.get_container_client("application_requests")
75
+ user_feedback_container = user_database.get_container_client("user_feedback")
76
 
77
  logger.info(f"user_container initialized: {user_container is not None}")
78
  logger.info(f"application_requests_container initialized: {application_requests_container is not None}")
79
+ logger.info(f"user_feedback_container initialized: {user_feedback_container is not None}")
80
 
81
  logger.info("Conexión a Cosmos DB SQL API exitosa")
82
  return True
 
195
  return False
196
 
197
  #######################################################################################################
198
+ def store_user_feedback(username, name, email, feedback):
199
+ global user_feedback_container
200
+ logger.info(f"Attempting to store user feedback for user: {username}")
201
+ try:
202
+ if user_feedback_container is None:
203
+ logger.error("user_feedback_container is not initialized")
204
+ return False
205
+
206
+ feedback_item = {
207
+ "id": str(uuid.uuid4()),
208
+ "username": username,
209
+ "name": name,
210
+ "email": email,
211
+ "feedback": feedback,
212
+ "timestamp": datetime.utcnow().isoformat()
213
+ }
214
+
215
+ result = user_feedback_container.create_item(body=feedback_item)
216
+ logger.info(f"User feedback stored with ID: {result['id']} for user: {username}")
217
+ return True
218
+ except Exception as e:
219
+ logger.error(f"Error storing user feedback for user {username}: {str(e)}")
220
+ return False
221
+
222
+
223
+ #######################################################################################################
224
+
225
  def store_morphosyntax_result(username, text, repeated_words, arc_diagrams, pos_analysis, morphological_analysis, sentence_structure):
226
  if analysis_collection is None:
227
  logger.error("La conexión a MongoDB no está inicializada")
modules/email/email.py CHANGED
@@ -49,4 +49,38 @@ def send_email_notification(name, email, institution, role, reason):
49
  return True
50
  except Exception as e:
51
  logger.error(f"Error sending email notification: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  return False
 
49
  return True
50
  except Exception as e:
51
  logger.error(f"Error sending email notification: {str(e)}")
52
+ return False
53
+
54
+ def send_user_feedback_notification(name, email, feedback):
55
+ sender_email = "[email protected]"
56
+ receiver_email = "[email protected]" # Cambia esto a la dirección que desees
57
+ password = os.environ.get("EMAIL_PASSWORD")
58
+
59
+ message = MIMEMultipart("alternative")
60
+ message["Subject"] = "Nuevo comentario de usuario en AIdeaText"
61
+ message["From"] = sender_email
62
+ message["To"] = receiver_email
63
+
64
+ html = f"""\
65
+ <html>
66
+ <body>
67
+ <h2>Nuevo comentario de usuario en AIdeaText</h2>
68
+ <p><strong>Nombre:</strong> {name}</p>
69
+ <p><strong>Email:</strong> {email}</p>
70
+ <p><strong>Comentario:</strong> {feedback}</p>
71
+ </body>
72
+ </html>
73
+ """
74
+
75
+ part = MIMEText(html, "html")
76
+ message.attach(part)
77
+
78
+ try:
79
+ with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
80
+ server.login(sender_email, password)
81
+ server.sendmail(sender_email, receiver_email, message.as_string())
82
+ logger.info(f"Email notification sent for user feedback from: {email}")
83
+ return True
84
+ except Exception as e:
85
+ logger.error(f"Error sending user feedback email notification: {str(e)}")
86
  return False
modules/ui/ui.py CHANGED
@@ -37,7 +37,8 @@ from ..database.database import (
37
  store_discourse_analysis_result,
38
  store_chat_history,
39
  create_admin_user,
40
- create_student_user
 
41
  )
42
 
43
  ######################################################
@@ -162,7 +163,7 @@ def user_page():
162
 
163
  # Aquí puedes añadir las funcionalidades para el usuario estudiante
164
  # Por ejemplo:
165
- tabs = st.tabs(["Análisis Morfosintáctico", "Análisis Semántico", "Análisis del Discurso", "Chat", "Mi Progreso"])
166
 
167
  with tabs[0]:
168
  display_morphosyntax_analysis_interface(nlp_models, 'es') # Asumiendo que 'es' es el idioma por defecto
@@ -174,6 +175,8 @@ def user_page():
174
  display_chatbot_interface('es')
175
  with tabs[4]:
176
  display_student_progress(st.session_state.username, 'es')
 
 
177
 
178
  ##################################################################################################
179
  def display_videos_and_info():
@@ -232,6 +235,37 @@ def register_form():
232
  st.error("Hubo un problema al enviar tu solicitud. Por favor, intenta de nuevo más tarde.")
233
  logger.error(f"Failed to store application request for {email}")
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
  ################################################################################
237
  def is_institutional_email(email):
 
37
  store_discourse_analysis_result,
38
  store_chat_history,
39
  create_admin_user,
40
+ create_student_user,
41
+ store_user_feedback
42
  )
43
 
44
  ######################################################
 
163
 
164
  # Aquí puedes añadir las funcionalidades para el usuario estudiante
165
  # Por ejemplo:
166
+ tabs = st.tabs(["Análisis Morfosintáctico", "Análisis Semántico", "Análisis del Discurso", "Chat", "Mi Progreso", "Formulario de Retroalimentación"])
167
 
168
  with tabs[0]:
169
  display_morphosyntax_analysis_interface(nlp_models, 'es') # Asumiendo que 'es' es el idioma por defecto
 
175
  display_chatbot_interface('es')
176
  with tabs[4]:
177
  display_student_progress(st.session_state.username, 'es')
178
+ with tabs[5]:
179
+ display_feedback_form('es')
180
 
181
  ##################################################################################################
182
  def display_videos_and_info():
 
235
  st.error("Hubo un problema al enviar tu solicitud. Por favor, intenta de nuevo más tarde.")
236
  logger.error(f"Failed to store application request for {email}")
237
 
238
+ ################################################################################
239
+ def display_feedback_form(lang_code):
240
+ translations = {
241
+ 'es': {
242
+ 'title': "Formulario de Retroalimentación",
243
+ 'name': "Nombre",
244
+ 'email': "Correo electrónico",
245
+ 'feedback': "Tu retroalimentación",
246
+ 'submit': "Enviar",
247
+ 'success': "¡Gracias por tu retroalimentación!",
248
+ 'error': "Hubo un problema al enviar el formulario. Por favor, intenta de nuevo."
249
+ },
250
+ # ... (traducciones para otros idiomas)
251
+ }
252
+
253
+ t = translations[lang_code]
254
+
255
+ st.header(t['title'])
256
+
257
+ name = st.text_input(t['name'])
258
+ email = st.text_input(t['email'])
259
+ feedback = st.text_area(t['feedback'])
260
+
261
+ if st.button(t['submit']):
262
+ if name and email and feedback:
263
+ if store_user_feedback(st.session_state.username, name, email, feedback):
264
+ st.success(t['success'])
265
+ else:
266
+ st.error(t['error'])
267
+ else:
268
+ st.warning("Por favor, completa todos los campos.")
269
 
270
  ################################################################################
271
  def is_institutional_email(email):