Update app.py
Browse files
app.py
CHANGED
@@ -85,7 +85,7 @@ def main_app():
|
|
85 |
'es': {
|
86 |
'title': "AIdeaText - Análisis morfológico y sintáctico",
|
87 |
'input_label': "Ingrese un texto para analizar (máx. 5,000 palabras):",
|
88 |
-
'input_placeholder': "El objetivo de esta aplicación es que mejore sus habilidades de redacción
|
89 |
'analyze_button': "Analizar texto",
|
90 |
'repeated_words': "Palabras repetidas",
|
91 |
'legend': "Leyenda: Categorías gramaticales",
|
@@ -94,74 +94,119 @@ def main_app():
|
|
94 |
'sentence': "Oración"
|
95 |
},
|
96 |
'en': {
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
},
|
99 |
'fr': {
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
}
|
103 |
|
104 |
# Use translations
|
105 |
t = translations[lang_code]
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
elif st.session_state.role == "Profesor":
|
153 |
# Código para la interfaz del profesor
|
154 |
st.write("Bienvenido, profesor. Aquí podrás ver el progreso de tus estudiantes.")
|
155 |
# Añade aquí la lógica para mostrar el progreso de los estudiantes
|
156 |
|
157 |
-
# Añadir sección de chatbot
|
158 |
-
st.header("Chat con AIdeaText")
|
159 |
-
user_input = st.text_input("Escribe tu mensaje aquí:")
|
160 |
-
if st.button("Enviar"):
|
161 |
-
if user_input:
|
162 |
-
response = get_chatbot_response(user_input)
|
163 |
-
st.text_area("Respuesta del chatbot:", value=response, height=100, max_chars=None, key=None)
|
164 |
-
|
165 |
def main():
|
166 |
if 'logged_in' not in st.session_state:
|
167 |
st.session_state.logged_in = False
|
|
|
85 |
'es': {
|
86 |
'title': "AIdeaText - Análisis morfológico y sintáctico",
|
87 |
'input_label': "Ingrese un texto para analizar (máx. 5,000 palabras):",
|
88 |
+
'input_placeholder': "El objetivo de esta aplicación es que mejore sus habilidades de redacción. Para ello, después de ingresar su texto y presionar el botón obtendrá tres vistas horizontales. La primera, le indicará las palabras que se repiten por categoría gramátical; la segunda, un diagrama de arco le indicara las conexiones sintácticas en cada oración; y la tercera, es un grafo en el cual visualizara la configuración de su texto.",
|
89 |
'analyze_button': "Analizar texto",
|
90 |
'repeated_words': "Palabras repetidas",
|
91 |
'legend': "Leyenda: Categorías gramaticales",
|
|
|
94 |
'sentence': "Oración"
|
95 |
},
|
96 |
'en': {
|
97 |
+
'title': "AIdeaText - Morphological and Syntactic Analysis",
|
98 |
+
'input_label': "Enter a text to analyze (max 5,000 words):",
|
99 |
+
'input_placeholder': "The goal of this app is for you to improve your writing skills. To do this, after entering your text and pressing the button you will get three horizontal views. The first will indicate the words that are repeated by grammatical category; second, an arc diagram will indicate the syntactic connections in each sentence; and the third is a graph in which you will visualize the configuration of your text.",
|
100 |
+
'analyze_button': "Analyze text",
|
101 |
+
'repeated_words': "Repeated words",
|
102 |
+
'legend': "Legend: Grammatical categories",
|
103 |
+
'arc_diagram': "Syntactic analysis: Arc diagram",
|
104 |
+
'network_diagram': "Syntactic analysis: Network diagram",
|
105 |
+
'sentence': "Sentence"
|
106 |
},
|
107 |
'fr': {
|
108 |
+
'title': "AIdeaText - Analyse morphologique et syntaxique",
|
109 |
+
'input_label': "Entrez un texte à analyser (max 5 000 mots) :",
|
110 |
+
'input_placeholder': "Le but de cette application est d'améliorer vos compétences en rédaction. Pour ce faire, après avoir saisi votre texte et appuyé sur le bouton vous obtiendrez trois vues horizontales. Le premier indiquera les mots répétés par catégorie grammaticale; deuxièmement, un diagramme en arcs indiquera les connexions syntaxiques dans chaque phrase; et le troisième est un graphique dans lequel vous visualiserez la configuration de votre texte.",
|
111 |
+
'analyze_button': "Analyser le texte",
|
112 |
+
'repeated_words': "Mots répétés",
|
113 |
+
'legend': "Légende : Catégories grammaticales",
|
114 |
+
'arc_diagram': "Analyse syntaxique : Diagramme en arc",
|
115 |
+
'network_diagram': "Analyse syntaxique : Diagramme de réseau",
|
116 |
+
'sentence': "Phrase"
|
117 |
}
|
118 |
}
|
119 |
|
120 |
# Use translations
|
121 |
t = translations[lang_code]
|
122 |
|
123 |
+
# Crear dos columnas: una para el chat y otra para el análisis
|
124 |
+
col1, col2 = st.columns([1, 2])
|
125 |
+
|
126 |
+
with col1:
|
127 |
+
st.markdown(f"### Chat con AIdeaText")
|
128 |
+
|
129 |
+
# Inicializar el historial de chat si no existe
|
130 |
+
if 'chat_history' not in st.session_state:
|
131 |
+
st.session_state.chat_history = []
|
132 |
+
|
133 |
+
# Mostrar el historial de chat
|
134 |
+
for i, (role, text) in enumerate(st.session_state.chat_history):
|
135 |
+
if role == "user":
|
136 |
+
st.text_area(f"Tú:", value=text, height=50, key=f"user_message_{i}", disabled=True)
|
137 |
+
else:
|
138 |
+
st.text_area(f"AIdeaText:", value=text, height=50, key=f"bot_message_{i}", disabled=True)
|
139 |
+
|
140 |
+
# Campo de entrada para el usuario
|
141 |
+
user_input = st.text_input("Escribe tu mensaje aquí:")
|
142 |
+
|
143 |
+
if st.button("Enviar"):
|
144 |
+
if user_input:
|
145 |
+
# Añadir mensaje del usuario al historial
|
146 |
+
st.session_state.chat_history.append(("user", user_input))
|
147 |
+
|
148 |
+
# Obtener respuesta del chatbot
|
149 |
+
response = get_chatbot_response(user_input)
|
150 |
+
|
151 |
+
# Añadir respuesta del chatbot al historial
|
152 |
+
st.session_state.chat_history.append(("bot", response))
|
153 |
+
|
154 |
+
# Limpiar el campo de entrada
|
155 |
+
st.experimental_rerun()
|
156 |
+
|
157 |
+
|
158 |
+
|
159 |
+
with col2:
|
160 |
+
st.markdown(f"### {t['title']}")
|
161 |
+
|
162 |
+
if st.session_state.role == "Estudiante":
|
163 |
+
# Código para la interfaz del estudiante
|
164 |
+
if 'input_text' not in st.session_state:
|
165 |
+
st.session_state.input_text = ""
|
166 |
+
|
167 |
+
sentence_input = st.text_area(t['input_label'], height=150, placeholder=t['input_placeholder'], value=st.session_state.input_text)
|
168 |
+
st.session_state.input_text = sentence_input
|
169 |
+
|
170 |
+
if st.button(t['analyze_button']):
|
171 |
+
if sentence_input:
|
172 |
+
doc = nlp_models[lang_code](sentence_input)
|
173 |
+
|
174 |
+
# Highlighted Repeated Words
|
175 |
+
with st.expander(t['repeated_words'], expanded=True):
|
176 |
+
word_colors = get_repeated_words_colors(doc)
|
177 |
+
highlighted_text = highlight_repeated_words(doc, word_colors)
|
178 |
+
st.markdown(highlighted_text, unsafe_allow_html=True)
|
179 |
+
|
180 |
+
# Legend for grammatical categories
|
181 |
+
st.markdown(f"##### {t['legend']}")
|
182 |
+
legend_html = "<div style='display: flex; flex-wrap: wrap;'>"
|
183 |
+
for pos, color in POS_COLORS.items():
|
184 |
+
if pos in POS_TRANSLATIONS:
|
185 |
+
legend_html += f"<div style='margin-right: 10px;'><span style='background-color: {color}; padding: 2px 5px;'>{POS_TRANSLATIONS[pos]}</span></div>"
|
186 |
+
legend_html += "</div>"
|
187 |
+
st.markdown(legend_html, unsafe_allow_html=True)
|
188 |
+
|
189 |
+
# Arc Diagram
|
190 |
+
with st.expander(t['arc_diagram'], expanded=True):
|
191 |
+
sentences = list(doc.sents)
|
192 |
+
for i, sent in enumerate(sentences):
|
193 |
+
st.subheader(f"{t['sentence']} {i+1}")
|
194 |
+
html = displacy.render(sent, style="dep", options={"distance": 100})
|
195 |
+
html = html.replace('height="375"', 'height="200"')
|
196 |
+
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|
197 |
+
html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"', lambda m: f'<g transform="translate({m.group(1)},50)"', html)
|
198 |
+
st.write(html, unsafe_allow_html=True)
|
199 |
+
|
200 |
+
# Network graph
|
201 |
+
with st.expander(t['network_diagram'], expanded=True):
|
202 |
+
fig = visualize_syntax(sentence_input, nlp_models[lang_code], lang_code)
|
203 |
+
st.pyplot(fig)
|
204 |
|
205 |
elif st.session_state.role == "Profesor":
|
206 |
# Código para la interfaz del profesor
|
207 |
st.write("Bienvenido, profesor. Aquí podrás ver el progreso de tus estudiantes.")
|
208 |
# Añade aquí la lógica para mostrar el progreso de los estudiantes
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
def main():
|
211 |
if 'logged_in' not in st.session_state:
|
212 |
st.session_state.logged_in = False
|