Update app.py
Browse files
app.py
CHANGED
@@ -8,118 +8,56 @@ import spacy
|
|
8 |
from spacy import displacy
|
9 |
import re
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
'fr': {
|
65 |
-
'title': "AIdeaText - Analyse morphologique et syntaxique",
|
66 |
-
'input_label': "Entrez un texte à analyser (max 5 000 mots) :",
|
67 |
-
'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.",
|
68 |
-
'analyze_button': "Analyser le texte",
|
69 |
-
'repeated_words': "Mots répétés",
|
70 |
-
'legend': "Légende : Catégories grammaticales",
|
71 |
-
'arc_diagram': "Analyse syntaxique : Diagramme en arc",
|
72 |
-
'network_diagram': "Analyse syntaxique : Diagramme de réseau",
|
73 |
-
'sentence': "Phrase"
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
# Use translations
|
78 |
-
t = translations[lang_code]
|
79 |
-
|
80 |
-
st.markdown(f"### {t['title']}")
|
81 |
-
|
82 |
-
# Initialize session state for input text if it doesn't exist
|
83 |
-
if 'input_text' not in st.session_state:
|
84 |
-
st.session_state.input_text = ""
|
85 |
-
|
86 |
-
# Text Input with instructions
|
87 |
-
sentence_input = st.text_area(t['input_label'], height=150, placeholder=t['input_placeholder'], value=st.session_state.input_text)
|
88 |
-
|
89 |
-
# Update session state with current input
|
90 |
-
st.session_state.input_text = sentence_input
|
91 |
-
|
92 |
-
if st.button(t['analyze_button']):
|
93 |
-
if sentence_input:
|
94 |
-
doc = nlp_models[lang_code](sentence_input)
|
95 |
-
|
96 |
-
# Highlighted Repeated Words
|
97 |
-
with st.expander(t['repeated_words'], expanded=True):
|
98 |
-
word_colors = get_repeated_words_colors(doc)
|
99 |
-
highlighted_text = highlight_repeated_words(doc, word_colors)
|
100 |
-
st.markdown(highlighted_text, unsafe_allow_html=True)
|
101 |
-
|
102 |
-
# Legend for grammatical categories
|
103 |
-
st.markdown(f"##### {t['legend']}")
|
104 |
-
legend_html = "<div style='display: flex; flex-wrap: wrap;'>"
|
105 |
-
for pos, color in POS_COLORS.items():
|
106 |
-
if pos in POS_TRANSLATIONS:
|
107 |
-
legend_html += f"<div style='margin-right: 10px;'><span style='background-color: {color}; padding: 2px 5px;'>{POS_TRANSLATIONS[pos]}</span></div>"
|
108 |
-
legend_html += "</div>"
|
109 |
-
st.markdown(legend_html, unsafe_allow_html=True)
|
110 |
-
|
111 |
-
# Arc Diagram
|
112 |
-
with st.expander(t['arc_diagram'], expanded=True):
|
113 |
-
sentences = list(doc.sents)
|
114 |
-
for i, sent in enumerate(sentences):
|
115 |
-
st.subheader(f"{t['sentence']} {i+1}")
|
116 |
-
html = displacy.render(sent, style="dep", options={"distance": 100})
|
117 |
-
html = html.replace('height="375"', 'height="200"')
|
118 |
-
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|
119 |
-
html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"', lambda m: f'<g transform="translate({m.group(1)},50)"', html)
|
120 |
-
st.write(html, unsafe_allow_html=True)
|
121 |
-
|
122 |
-
# Network graph
|
123 |
-
with st.expander(t['network_diagram'], expanded=True):
|
124 |
-
fig = visualize_syntax(sentence_input, nlp_models[lang_code], lang_code)
|
125 |
-
st.pyplot(fig)
|
|
|
8 |
from spacy import displacy
|
9 |
import re
|
10 |
|
11 |
+
from modules.auth import register_user, authenticate_user
|
12 |
+
from modules.morpho_analysis import get_repeated_words_colors, highlight_repeated_words, POS_COLORS, POS_TRANSLATIONS
|
13 |
+
from modules.syntax_analysis import visualize_syntax
|
14 |
+
|
15 |
+
# ... (resto de tus importaciones y configuraciones)
|
16 |
+
|
17 |
+
def login_page():
|
18 |
+
st.title("Iniciar Sesión")
|
19 |
+
username = st.text_input("Usuario")
|
20 |
+
password = st.text_input("Contraseña", type='password')
|
21 |
+
if st.button("Iniciar Sesión"):
|
22 |
+
if authenticate_user(username, password):
|
23 |
+
st.success(f"Bienvenido, {username}!")
|
24 |
+
st.session_state.logged_in = True
|
25 |
+
st.session_state.username = username
|
26 |
+
st.experimental_rerun()
|
27 |
+
else:
|
28 |
+
st.error("Usuario o contraseña incorrectos")
|
29 |
+
|
30 |
+
def register_page():
|
31 |
+
st.title("Registrarse")
|
32 |
+
new_username = st.text_input("Nuevo Usuario")
|
33 |
+
new_password = st.text_input("Nueva Contraseña", type='password')
|
34 |
+
role = st.selectbox("Rol", ["Estudiante", "Profesor"])
|
35 |
+
if st.button("Registrarse"):
|
36 |
+
if register_user(new_username, new_password, role):
|
37 |
+
st.success("Registro exitoso. Por favor, inicia sesión.")
|
38 |
+
else:
|
39 |
+
st.error("El usuario ya existe")
|
40 |
+
|
41 |
+
def main_app():
|
42 |
+
# Aquí va tu código principal de la aplicación
|
43 |
+
# ... (el resto de tu código actual en app.py)
|
44 |
+
|
45 |
+
def main():
|
46 |
+
if 'logged_in' not in st.session_state:
|
47 |
+
st.session_state.logged_in = False
|
48 |
+
|
49 |
+
if not st.session_state.logged_in:
|
50 |
+
menu = ["Iniciar Sesión", "Registrarse"]
|
51 |
+
choice = st.sidebar.selectbox("Menu", menu)
|
52 |
+
if choice == "Iniciar Sesión":
|
53 |
+
login_page()
|
54 |
+
elif choice == "Registrarse":
|
55 |
+
register_page()
|
56 |
+
else:
|
57 |
+
if st.sidebar.button("Cerrar Sesión"):
|
58 |
+
st.session_state.logged_in = False
|
59 |
+
st.experimental_rerun()
|
60 |
+
main_app()
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|