fixes
Browse files
app.py
CHANGED
@@ -66,7 +66,8 @@ def main():
|
|
66 |
background-color: #ffe066;
|
67 |
border-bottom: 2px dotted #ff9900;
|
68 |
position: relative;
|
69 |
-
color: black !important;
|
|
|
70 |
}
|
71 |
|
72 |
/* Стиль для контейнера с результатом */
|
@@ -81,11 +82,13 @@ def main():
|
|
81 |
</style>
|
82 |
""", unsafe_allow_html=True)
|
83 |
|
84 |
-
|
85 |
st.title('Проверка орфографии')
|
86 |
text = st.text_area("Введите текст для проверки:", height=200).replace("\n", " ")
|
87 |
tool = load_assets()
|
88 |
|
|
|
|
|
|
|
89 |
if st.button('Проверить текст'):
|
90 |
if not text.strip():
|
91 |
st.warning("Введите текст для проверки")
|
@@ -100,12 +103,13 @@ def main():
|
|
100 |
highlighted = []
|
101 |
last_pos = 0
|
102 |
|
103 |
-
for error in sorted_errors:
|
104 |
highlighted.append(html.escape(text[last_pos:error['start']]))
|
105 |
|
|
|
106 |
highlighted.append(
|
107 |
-
f'<span
|
108 |
-
f'
|
109 |
f'{html.escape(text[error["start"]:error["end"]])}'
|
110 |
f'</span>'
|
111 |
)
|
@@ -126,14 +130,32 @@ def main():
|
|
126 |
">
|
127 |
{''.join(highlighted)}
|
128 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
"""
|
130 |
|
131 |
st.markdown("### Результат проверки:")
|
132 |
st.markdown(html_content, unsafe_allow_html=True)
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
|
139 |
if __name__ == "__main__":
|
|
|
66 |
background-color: #ffe066;
|
67 |
border-bottom: 2px dotted #ff9900;
|
68 |
position: relative;
|
69 |
+
color: black !important;
|
70 |
+
cursor: pointer;
|
71 |
}
|
72 |
|
73 |
/* Стиль для контейнера с результатом */
|
|
|
82 |
</style>
|
83 |
""", unsafe_allow_html=True)
|
84 |
|
|
|
85 |
st.title('Проверка орфографии')
|
86 |
text = st.text_area("Введите текст для проверки:", height=200).replace("\n", " ")
|
87 |
tool = load_assets()
|
88 |
|
89 |
+
# Создаем контейнер для всплывающих сообщений
|
90 |
+
popup_container = st.empty()
|
91 |
+
|
92 |
if st.button('Проверить текст'):
|
93 |
if not text.strip():
|
94 |
st.warning("Введите текст для проверки")
|
|
|
103 |
highlighted = []
|
104 |
last_pos = 0
|
105 |
|
106 |
+
for i, error in enumerate(sorted_errors):
|
107 |
highlighted.append(html.escape(text[last_pos:error['start']]))
|
108 |
|
109 |
+
# Добавляем обработчик клика с уникальным ID для каждой ошибки
|
110 |
highlighted.append(
|
111 |
+
f'<span class="error-highlight" onclick="showError({i})" '
|
112 |
+
f'id="error-{i}" title="{html.escape(error["message"])}">'
|
113 |
f'{html.escape(text[error["start"]:error["end"]])}'
|
114 |
f'</span>'
|
115 |
)
|
|
|
130 |
">
|
131 |
{''.join(highlighted)}
|
132 |
</div>
|
133 |
+
|
134 |
+
<script>
|
135 |
+
function showError(errorIndex) {{
|
136 |
+
// Отправляем сообщение в Streamlit с индексом ошибки
|
137 |
+
window.parent.postMessage({{
|
138 |
+
type: 'streamlit:component',
|
139 |
+
component: 'error_click',
|
140 |
+
data: errorIndex
|
141 |
+
}}, '*');
|
142 |
+
}}
|
143 |
+
</script>
|
144 |
"""
|
145 |
|
146 |
st.markdown("### Результат проверки:")
|
147 |
st.markdown(html_content, unsafe_allow_html=True)
|
148 |
|
149 |
+
# Сохраняем ошибки в session_state для доступа из обработчика
|
150 |
+
st.session_state.errors = errors
|
151 |
+
|
152 |
+
# Обработчик кликов по ошибкам
|
153 |
+
if 'errors' in st.session_state:
|
154 |
+
clicked_error = st.experimental_get_query_params().get("error_click")
|
155 |
+
if clicked_error:
|
156 |
+
error_index = int(clicked_error[0])
|
157 |
+
error = st.session_state.errors[error_index]
|
158 |
+
st.warning(f"Ошибка: {error['message']}")
|
159 |
|
160 |
|
161 |
if __name__ == "__main__":
|