xiaolv commited on
Commit
2712829
1 Parent(s): 1784e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -81,6 +81,28 @@ def get_content_type(file_path):
81
  return 'application/octet-stream'
82
 
83
  def upload_attachment(cookie ,organization_id,file_path):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  url = 'https://claude.ai/api/convert_document'
85
  headers = {
86
  'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.82',
 
81
  return 'application/octet-stream'
82
 
83
  def upload_attachment(cookie ,organization_id,file_path):
84
+ ## 自己解析
85
+ if file_path.endswith(('.txt', '.pdf', '.csv')):
86
+ file_name = os.path.basename(file_path)
87
+ file_size = os.path.getsize(file_path)
88
+ file_type = "text/plain"
89
+ with open(file_path, 'r', encoding='utf-8') as file:
90
+ file_content = file.read()
91
+ print({
92
+ "file_name": file_name,
93
+ "file_type": file_type,
94
+ "file_size": file_size,
95
+ "extracted_content": file_content})
96
+
97
+ return {
98
+ "file_name": file_name,
99
+ "file_type": file_type,
100
+ "file_size": file_size,
101
+ "extracted_content": file_content
102
+ }
103
+
104
+
105
+
106
  url = 'https://claude.ai/api/convert_document'
107
  headers = {
108
  'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.82',