初始化项目,由ModelHub XC社区提供模型
Model: chatpbc1/chatpbc-v33 Source: Original Platform
This commit is contained in:
30
chatpbc_file_processor.py
Normal file
30
chatpbc_file_processor.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user