Files
chatpbc-v33/chatpbc_file_processor.py
ModelHub XC f61e872e5c 初始化项目,由ModelHub XC社区提供模型
Model: chatpbc1/chatpbc-v33
Source: Original Platform
2026-08-02 21:17:18 +08:00

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)