chatpbc-v33 / chatpbc_file_processor.py
chatpbc1's picture
Upload chatpbc_file_processor.py with huggingface_hub
1ce10f0 verified
Raw
History Blame Contribute Delete
1.01 kB
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)