File size: 1,006 Bytes
1ce10f0
 
 
 
 
 
 
 
 
6e94b5b
1ce10f0
 
 
 
 
 
 
 
6e94b5b
1ce10f0
6e94b5b
1ce10f0
 
 
 
 
6e94b5b
1ce10f0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)