bvd757 commited on
Commit
0498a33
·
1 Parent(s): 1fa20bd
Files changed (2) hide show
  1. app.py +33 -5
  2. requirements.txt +1 -0
app.py CHANGED
@@ -4,6 +4,8 @@ import streamlit as st
4
  import subprocess
5
  from pathlib import Path
6
  import html
 
 
7
 
8
  is_java_installed = False
9
  prompt = """
@@ -85,16 +87,24 @@ def check_text(text, tool):
85
  errors = sorted(errors, key=lambda x: x['end'])
86
 
87
  shift = 0
88
- for i, error in enumerate(errors):
89
  error['start'] += shift
90
  error['end'] += shift
91
- inp = f"({i + 1})"
92
  text = text[:error['end']] + inp + text[error['end']:]
93
  shift += len(inp)
94
 
95
  return text, errors
96
 
97
 
 
 
 
 
 
 
 
 
98
  def main():
99
  st.markdown("""
100
  <style>
@@ -123,9 +133,27 @@ def main():
123
  </style>
124
  """, unsafe_allow_html=True)
125
 
126
-
127
  st.title('Проверка орфографии')
128
- text = st.text_area("Введите текст для проверки:", height=200).replace("\n", " ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  tool = load_assets()
130
 
131
  if st.button('Проверить текст'):
@@ -174,7 +202,7 @@ def main():
174
 
175
  st.markdown("### Найденные ошибки:")
176
  for i, error in enumerate(errors, 1):
177
- st.markdown(f"{i}. **Позиция {error['start']}-{error['end']}**: {error['message']}")
178
 
179
 
180
  if __name__ == "__main__":
 
4
  import subprocess
5
  from pathlib import Path
6
  import html
7
+ import docx
8
+ from io import BytesIO
9
 
10
  is_java_installed = False
11
  prompt = """
 
87
  errors = sorted(errors, key=lambda x: x['end'])
88
 
89
  shift = 0
90
+ for i, error in enumerate(errors, 1):
91
  error['start'] += shift
92
  error['end'] += shift
93
+ inp = f"({i})"
94
  text = text[:error['end']] + inp + text[error['end']:]
95
  shift += len(inp)
96
 
97
  return text, errors
98
 
99
 
100
+ def extract_text_from_docx(file):
101
+ doc = docx.Document(BytesIO(file.getvalue()))
102
+ full_text = []
103
+ for para in doc.paragraphs:
104
+ full_text.append(para.text)
105
+ return "\n".join(full_text)
106
+
107
+
108
  def main():
109
  st.markdown("""
110
  <style>
 
133
  </style>
134
  """, unsafe_allow_html=True)
135
 
 
136
  st.title('Проверка орфографии')
137
+
138
+ # Добавляем переключатель между режимами ввода
139
+ input_mode = st.radio(
140
+ "Выберите способ ввода текста:",
141
+ ("Ввести текст вручную", "Загрузить Word документ"),
142
+ horizontal=True
143
+ )
144
+
145
+ text = ""
146
+ if input_mode == "Загрузить Word документ":
147
+ uploaded_file = st.file_uploader("Загрузите Word документ", type=['docx'])
148
+ if uploaded_file is not None:
149
+ try:
150
+ text = extract_text_from_docx(uploaded_file)
151
+ st.text_area("Текст из документа:", value=text, height=200, key="docx_text")
152
+ except Exception as e:
153
+ st.error(f"Ошибка при чтении файла: {e}")
154
+ else:
155
+ text = st.text_area("Введите текст для проверки:", height=200, key="manual_text").replace("\n", " ")
156
+
157
  tool = load_assets()
158
 
159
  if st.button('Проверить текст'):
 
202
 
203
  st.markdown("### Найденные ошибки:")
204
  for i, error in enumerate(errors, 1):
205
+ st.markdown(f"{i}. {error['message']}")
206
 
207
 
208
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -21,6 +21,7 @@ propcache==0.3.1
21
  psutil==7.0.0
22
  pydantic==2.11.3
23
  pydantic_core==2.33.1
 
24
  requests==2.32.3
25
  setuptools==78.1.0
26
  sniffio==1.3.1
 
21
  psutil==7.0.0
22
  pydantic==2.11.3
23
  pydantic_core==2.33.1
24
+ python-docx==0.8.11
25
  requests==2.32.3
26
  setuptools==78.1.0
27
  sniffio==1.3.1