Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import docx
|
4 |
|
5 |
def process_input(uploaded_file, function):
|
@@ -7,8 +7,8 @@ def process_input(uploaded_file, function):
|
|
7 |
return "Файл не загружен"
|
8 |
|
9 |
try:
|
10 |
-
#
|
11 |
-
file_content = uploaded_file.
|
12 |
|
13 |
# Определяем тип файла по расширению
|
14 |
if uploaded_file.name.endswith('.txt'):
|
@@ -16,7 +16,7 @@ def process_input(uploaded_file, function):
|
|
16 |
content = file_content.decode("utf-8")
|
17 |
elif uploaded_file.name.endswith('.docx'):
|
18 |
# Если файл Word, используем библиотеку python-docx
|
19 |
-
doc = docx.Document(BytesIO(file_content))
|
20 |
content = '\n'.join([para.text for para in doc.paragraphs])
|
21 |
else:
|
22 |
return "Неподдерживаемый тип файла"
|
|
|
1 |
import gradio as gr
|
2 |
+
import io
|
3 |
import docx
|
4 |
|
5 |
def process_input(uploaded_file, function):
|
|
|
7 |
return "Файл не загружен"
|
8 |
|
9 |
try:
|
10 |
+
# Читаем содержимое файла
|
11 |
+
file_content = io.BytesIO(uploaded_file).read()
|
12 |
|
13 |
# Определяем тип файла по расширению
|
14 |
if uploaded_file.name.endswith('.txt'):
|
|
|
16 |
content = file_content.decode("utf-8")
|
17 |
elif uploaded_file.name.endswith('.docx'):
|
18 |
# Если файл Word, используем библиотеку python-docx
|
19 |
+
doc = docx.Document(io.BytesIO(file_content))
|
20 |
content = '\n'.join([para.text for para in doc.paragraphs])
|
21 |
else:
|
22 |
return "Неподдерживаемый тип файла"
|