Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            # | 
| 2 | 
             
            #app.py
         | 
| 3 | 
             
            import logging
         | 
| 4 | 
             
            import streamlit as st
         | 
| @@ -7,27 +7,6 @@ import os | |
| 7 | 
             
            from dotenv import load_dotenv
         | 
| 8 | 
             
            from datetime import datetime
         | 
| 9 |  | 
| 10 | 
            -
            #def setup_logging():
         | 
| 11 | 
            -
            #    log_dir = 'logs'
         | 
| 12 | 
            -
            #    if not os.path.exists(log_dir):
         | 
| 13 | 
            -
            #        os.makedirs(log_dir)
         | 
| 14 | 
            -
            #    current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
         | 
| 15 | 
            -
            #    log_filename = f'{log_dir}/app_log_{current_time}.txt'
         | 
| 16 | 
            -
            #    logging.basicConfig(
         | 
| 17 | 
            -
            #        level=logging.DEBUG,
         | 
| 18 | 
            -
            #        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
         | 
| 19 | 
            -
            #        filename=log_filename,
         | 
| 20 | 
            -
            #        filemode='w'
         | 
| 21 | 
            -
            #    )
         | 
| 22 | 
            -
            #    console = logging.StreamHandler()
         | 
| 23 | 
            -
            #    console.setLevel(logging.INFO)
         | 
| 24 | 
            -
            #    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
         | 
| 25 | 
            -
            #    console.setFormatter(formatter)
         | 
| 26 | 
            -
            #    logging.getLogger('').addHandler(console)
         | 
| 27 | 
            -
            #    logging.info(f"Logging iniciado. Archivo de log: {log_filename}")
         | 
| 28 | 
            -
             | 
| 29 | 
            -
            #setup_logging()
         | 
| 30 | 
            -
             | 
| 31 | 
             
            load_dotenv()
         | 
| 32 |  | 
| 33 | 
             
            st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
         | 
| @@ -36,13 +15,12 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| 36 |  | 
| 37 | 
             
            #########IMPORTACIONES LOCALES#######################################
         | 
| 38 | 
             
            from translations import get_translations
         | 
| 39 | 
            -
             | 
| 40 | 
             
            from session_state import initialize_session_state
         | 
| 41 | 
            -
             | 
| 42 | 
             
            from modules.ui.ui import main as ui_main
         | 
| 43 | 
            -
             | 
| 44 | 
             
            from modules.utils.spacy_utils import load_spacy_models
         | 
|  | |
| 45 |  | 
|  | |
| 46 | 
             
            from modules.morphosyntax.morphosyntax_interface import (
         | 
| 47 | 
             
                display_morphosyntax_interface, 
         | 
| 48 | 
             
                display_morphosyntax_results
         | 
| @@ -53,11 +31,8 @@ from modules.semantic.semantic_interface import ( | |
| 53 | 
             
                display_semantic_results
         | 
| 54 | 
             
            )
         | 
| 55 |  | 
| 56 | 
            -
             | 
| 57 | 
            -
            from modules.database.database_init import  | 
| 58 | 
            -
                initialize_database_connections
         | 
| 59 | 
            -
            )
         | 
| 60 | 
            -
             | 
| 61 | 
             
            from modules.database.sql_db import (
         | 
| 62 | 
             
                create_student_user,
         | 
| 63 | 
             
                get_student_user,
         | 
| @@ -80,32 +55,30 @@ from modules.database.morphosintax_mongo_db import ( | |
| 80 | 
             
                get_student_morphosyntax_analysis
         | 
| 81 | 
             
            )
         | 
| 82 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 83 | 
             
            from modules.database.chat_db import (
         | 
| 84 | 
             
                store_chat_history,
         | 
| 85 | 
             
                get_chat_history
         | 
| 86 | 
             
            )
         | 
| 87 |  | 
| 88 | 
            -
            from modules.studentact.student_activities_v2 import  | 
| 89 | 
            -
                display_student_progress
         | 
| 90 | 
            -
            )
         | 
| 91 | 
            -
             | 
| 92 | 
             
            from modules.auth.auth import (
         | 
| 93 | 
             
                authenticate_student,
         | 
| 94 | 
             
                register_student,
         | 
| 95 | 
             
                update_student_info,
         | 
| 96 | 
             
                delete_student
         | 
| 97 | 
             
            )
         | 
| 98 | 
            -
             | 
| 99 | 
             
            from modules.admin.admin_ui import admin_page
         | 
| 100 | 
            -
             | 
| 101 | 
             
            from modules.chatbot.chatbot import (
         | 
| 102 | 
             
                initialize_chatbot,
         | 
| 103 | 
             
                process_chat_input
         | 
| 104 | 
             
            )
         | 
| 105 |  | 
| 106 | 
             
            print("Configurando página")
         | 
| 107 | 
            -
            # st.cache_data.clear()
         | 
| 108 | 
            -
            # st.cache_resource.clear()
         | 
| 109 |  | 
| 110 | 
             
            logging.basicConfig(level=logging.INFO)
         | 
| 111 | 
             
            logger = logging.getLogger(__name__)
         | 
| @@ -134,12 +107,22 @@ def app_main(): | |
| 134 | 
             
                        st.session_state.nlp_models = initialize_nlp_models()
         | 
| 135 | 
             
                        logger.info("Modelos NLP inicializados y almacenados en la sesión")
         | 
| 136 |  | 
| 137 | 
            -
                    # Inicializar  | 
|  | |
|  | |
|  | |
|  | |
| 138 | 
             
                    if 'morphosyntax_state' not in st.session_state:
         | 
| 139 | 
             
                        st.session_state.morphosyntax_state = {
         | 
| 140 | 
             
                            'last_analysis': None,
         | 
| 141 | 
             
                            'analysis_count': 0
         | 
| 142 | 
             
                        }
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 143 |  | 
| 144 | 
             
                    # Configurar la página inicial si no está configurada
         | 
| 145 | 
             
                    if 'page' not in st.session_state:
         | 
| @@ -155,8 +138,9 @@ def app_main(): | |
| 155 | 
             
                except Exception as e:
         | 
| 156 | 
             
                    logger.error(f"Error en app_main: {str(e)}", exc_info=True)
         | 
| 157 | 
             
                    st.error("Se ha producido un error en la aplicación. Por favor, inténtelo de nuevo más tarde.")
         | 
| 158 | 
            -
                    if st.button("Reiniciar aplicación" | 
| 159 | 
            -
             | 
|  | |
| 160 | 
             
                        st.rerun()
         | 
| 161 |  | 
| 162 | 
             
            if __name__ == "__main__":
         | 
|  | |
| 1 | 
            +
            #AIdeaText V3
         | 
| 2 | 
             
            #app.py
         | 
| 3 | 
             
            import logging
         | 
| 4 | 
             
            import streamlit as st
         | 
|  | |
| 7 | 
             
            from dotenv import load_dotenv
         | 
| 8 | 
             
            from datetime import datetime
         | 
| 9 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 10 | 
             
            load_dotenv()
         | 
| 11 |  | 
| 12 | 
             
            st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
         | 
|  | |
| 15 |  | 
| 16 | 
             
            #########IMPORTACIONES LOCALES#######################################
         | 
| 17 | 
             
            from translations import get_translations
         | 
|  | |
| 18 | 
             
            from session_state import initialize_session_state
         | 
|  | |
| 19 | 
             
            from modules.ui.ui import main as ui_main
         | 
|  | |
| 20 | 
             
            from modules.utils.spacy_utils import load_spacy_models
         | 
| 21 | 
            +
            from modules.utils.widget_utils import generate_unique_key
         | 
| 22 |  | 
| 23 | 
            +
            # Importaciones de interfaces
         | 
| 24 | 
             
            from modules.morphosyntax.morphosyntax_interface import (
         | 
| 25 | 
             
                display_morphosyntax_interface, 
         | 
| 26 | 
             
                display_morphosyntax_results
         | 
|  | |
| 31 | 
             
                display_semantic_results
         | 
| 32 | 
             
            )
         | 
| 33 |  | 
| 34 | 
            +
            # Importaciones de base de datos
         | 
| 35 | 
            +
            from modules.database.database_init import initialize_database_connections
         | 
|  | |
|  | |
|  | |
| 36 | 
             
            from modules.database.sql_db import (
         | 
| 37 | 
             
                create_student_user,
         | 
| 38 | 
             
                get_student_user,
         | 
|  | |
| 55 | 
             
                get_student_morphosyntax_analysis
         | 
| 56 | 
             
            )
         | 
| 57 |  | 
| 58 | 
            +
            from modules.database.semantic_mongo_db import (
         | 
| 59 | 
            +
                store_student_semantic_result,
         | 
| 60 | 
            +
                get_student_semantic_analysis
         | 
| 61 | 
            +
            )
         | 
| 62 | 
            +
             | 
| 63 | 
             
            from modules.database.chat_db import (
         | 
| 64 | 
             
                store_chat_history,
         | 
| 65 | 
             
                get_chat_history
         | 
| 66 | 
             
            )
         | 
| 67 |  | 
| 68 | 
            +
            from modules.studentact.student_activities_v2 import display_student_progress
         | 
|  | |
|  | |
|  | |
| 69 | 
             
            from modules.auth.auth import (
         | 
| 70 | 
             
                authenticate_student,
         | 
| 71 | 
             
                register_student,
         | 
| 72 | 
             
                update_student_info,
         | 
| 73 | 
             
                delete_student
         | 
| 74 | 
             
            )
         | 
|  | |
| 75 | 
             
            from modules.admin.admin_ui import admin_page
         | 
|  | |
| 76 | 
             
            from modules.chatbot.chatbot import (
         | 
| 77 | 
             
                initialize_chatbot,
         | 
| 78 | 
             
                process_chat_input
         | 
| 79 | 
             
            )
         | 
| 80 |  | 
| 81 | 
             
            print("Configurando página")
         | 
|  | |
|  | |
| 82 |  | 
| 83 | 
             
            logging.basicConfig(level=logging.INFO)
         | 
| 84 | 
             
            logger = logging.getLogger(__name__)
         | 
|  | |
| 107 | 
             
                        st.session_state.nlp_models = initialize_nlp_models()
         | 
| 108 | 
             
                        logger.info("Modelos NLP inicializados y almacenados en la sesión")
         | 
| 109 |  | 
| 110 | 
            +
                    # Inicializar contador de widgets si no existe
         | 
| 111 | 
            +
                    if 'widget_counter' not in st.session_state:
         | 
| 112 | 
            +
                        st.session_state.widget_counter = 0
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                    # Inicializar estados de análisis si no existen
         | 
| 115 | 
             
                    if 'morphosyntax_state' not in st.session_state:
         | 
| 116 | 
             
                        st.session_state.morphosyntax_state = {
         | 
| 117 | 
             
                            'last_analysis': None,
         | 
| 118 | 
             
                            'analysis_count': 0
         | 
| 119 | 
             
                        }
         | 
| 120 | 
            +
                        
         | 
| 121 | 
            +
                    if 'semantic_state' not in st.session_state:
         | 
| 122 | 
            +
                        st.session_state.semantic_state = {
         | 
| 123 | 
            +
                            'last_analysis': None,
         | 
| 124 | 
            +
                            'analysis_count': 0
         | 
| 125 | 
            +
                        }
         | 
| 126 |  | 
| 127 | 
             
                    # Configurar la página inicial si no está configurada
         | 
| 128 | 
             
                    if 'page' not in st.session_state:
         | 
|  | |
| 138 | 
             
                except Exception as e:
         | 
| 139 | 
             
                    logger.error(f"Error en app_main: {str(e)}", exc_info=True)
         | 
| 140 | 
             
                    st.error("Se ha producido un error en la aplicación. Por favor, inténtelo de nuevo más tarde.")
         | 
| 141 | 
            +
                    if st.button("Reiniciar aplicación", 
         | 
| 142 | 
            +
                                key=generate_unique_key("app", "reset_button")):
         | 
| 143 | 
            +
                        st.session_state.clear()
         | 
| 144 | 
             
                        st.rerun()
         | 
| 145 |  | 
| 146 | 
             
            if __name__ == "__main__":
         | 
