31 lines
1006 B
Python
31 lines
1006 B
Python
import os
|
|
|
|
def process_file(file_path):
|
|
"""
|
|
Processes uploaded business documents to extract text for analysis.
|
|
"""
|
|
_, extension = os.path.splitext(file_path)
|
|
extension = extension.lower()
|
|
|
|
try:
|
|
if extension == '.txt':
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
return f.read()
|
|
elif extension == '.md':
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
return f.read()
|
|
else:
|
|
return f"Unsupported file type: {extension}. Currently only .txt and .md are supported for direct extraction."
|
|
except Exception as e:
|
|
return f"Error processing file: {str(e)}"
|
|
|
|
if __name__ == "__main__":
|
|
# Test with a dummy file
|
|
test_file = "test_doc.txt"
|
|
with open(test_file, "w") as f:
|
|
f.write("This is a sample business document for ChatPBC analysis.")
|
|
|
|
content = process_file(test_file)
|
|
print(f"Processed file content: {content}")
|
|
os.remove(test_file)
|