EGYADMIN commited on
Commit
275f63b
·
verified ·
1 Parent(s): 25d8bd2

Update modules/ai_assistant/ai_app.py

Browse files
Files changed (1) hide show
  1. modules/ai_assistant/ai_app.py +18 -18
modules/ai_assistant/ai_app.py CHANGED
@@ -111,30 +111,30 @@ class ClaudeAIService:
111
  with open(image_path, 'rb') as f:
112
  file_content = f.read()
113
  else:
114
- # استخدام الملف الأصلي للملفات غير الصور أو الصور الصغيرة
115
- with open(image_path, 'rb') as f:
116
- file_content = f.read()
117
 
118
- # التحقق من حجم الملف بعد القراءة
119
- if len(file_content) > 5 * 1024 * 1024:
120
- raise ValueError(f"حجم الملف ({len(file_content)/1024/1024:.2f} ميجابايت) يتجاوز الحد الأقصى (5 ميجابايت). يرجى تقليل حجم الملف قبل الرفع.")
121
 
122
- # تحويل المحتوى إلى Base64
123
- file_base64 = base64.b64encode(file_content).decode('utf-8')
124
 
125
 
126
- except Exception as e:
127
- logging.error(f"خطأ أثناء ضغط الصورة: {str(e)}")
128
- with open(image_path, 'rb') as f:
 
 
 
 
129
  file_content = f.read()
130
- else:
131
- # استخدام الملف الأصلي للملفات غير الصور أو الصور الصغيرة
132
- with open(image_path, 'rb') as f:
133
- file_content = f.read()
134
 
135
- # التحقق من حجم الملف بعد القراءة
136
- if len(file_content) > 5 * 1024 * 1024:
137
- raise ValueError(f"حجم الملف ({len(file_content)/1024/1024:.2f} ميجابايت) يتجاوز الحد الأقصى (5 ميجابايت). يرجى تقليل حجم الملف قبل الرفع.")
138
 
139
 
140
 
 
111
  with open(image_path, 'rb') as f:
112
  file_content = f.read()
113
  else:
114
+ # استخدام الملف الأصلي للملفات غير الصور أو الصور الصغيرة
115
+ with open(image_path, 'rb') as f:
116
+ file_content = f.read()
117
 
118
+ # التحقق من حجم الملف بعد القراءة
119
+ if len(file_content) > 5 * 1024 * 1024:
120
+ raise ValueError(f"حجم الملف ({len(file_content)/1024/1024:.2f} ميجابايت) يتجاوز الحد الأقصى (5 ميجابايت). يرجى تقليل حجم الملف قبل الرفع.")
121
 
122
+ # تحويل المحتوى إلى Base64
123
+ file_base64 = base64.b64encode(file_content).decode('utf-8')
124
 
125
 
126
+ except Exception as e:
127
+ logging.error(f"خطأ أثناء ضغط الصورة: {str(e)}")
128
+ with open(image_path, 'rb') as f:
129
+ file_content = f.read()
130
+ else:
131
+ # استخدام الملف الأصلي للملفات غير الصور أو الصور الصغيرة
132
+ with open(image_path, 'rb') as f:
133
  file_content = f.read()
 
 
 
 
134
 
135
+ # التحقق من حجم الملف بعد القراءة
136
+ if len(file_content) > 5 * 1024 * 1024:
137
+ raise ValueError(f"حجم الملف ({len(file_content)/1024/1024:.2f} ميجابايت) يتجاوز الحد الأقصى (5 ميجابايت). يرجى تقليل حجم الملف قبل الرفع.")
138
 
139
 
140