Spaces:
Sleeping
Sleeping
Update helper.py
Browse files
helper.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import json
|
|
|
2 |
|
3 |
def open_file(filepath):
|
4 |
with open(filepath, 'r', encoding='utf-8') as infile:
|
@@ -10,4 +11,13 @@ def save_file(filepath, content):
|
|
10 |
|
11 |
def append_file(filepath, content):
|
12 |
with open(filepath, 'w', encoding='utf-8') as outfile:
|
13 |
-
outfile.write(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
+
from docx import Document
|
3 |
|
4 |
def open_file(filepath):
|
5 |
with open(filepath, 'r', encoding='utf-8') as infile:
|
|
|
11 |
|
12 |
def append_file(filepath, content):
|
13 |
with open(filepath, 'w', encoding='utf-8') as outfile:
|
14 |
+
outfile.write(content)
|
15 |
+
|
16 |
+
def read_word_document(filepath):
|
17 |
+
try:
|
18 |
+
doc = Document(filepath)
|
19 |
+
paragraphs = [p.text for p in doc.paragraphs]
|
20 |
+
return paragraphs
|
21 |
+
except Exception as e:
|
22 |
+
print(f"Error reading the Word document: {e}")
|
23 |
+
return []
|