Omartificial-Intelligence-Space commited on
Commit
0a6b1c6
Β·
verified Β·
1 Parent(s): ff22674

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -21,6 +21,9 @@ if GOOGLE_API_KEY is None:
21
  app = Flask(__name__)
22
  CORS(app)
23
 
 
 
 
24
  # Initialize Gemini client with correct API key
25
  client = genai.Client(api_key=GOOGLE_API_KEY)
26
 
@@ -341,6 +344,7 @@ HTML_TEMPLATE = """
341
  <div class="upload-area" id="uploadArea">
342
  <div class="upload-icon">πŸ“„</div>
343
  <p>Drag and drop your PDF file here, or click to select</p>
 
344
  <input type="file" id="fileInput" class="file-input" accept=".pdf">
345
  <button class="upload-btn" onclick="document.getElementById('fileInput').click()">
346
  Choose PDF File
@@ -427,6 +431,12 @@ HTML_TEMPLATE = """
427
  return;
428
  }
429
 
 
 
 
 
 
 
430
  showLoading('Uploading PDF...');
431
 
432
  const formData = new FormData();
@@ -606,13 +616,13 @@ def upload_file():
606
  if file.filename == '':
607
  return jsonify({'success': False, 'error': 'No file selected'})
608
 
609
- # Check file size (limit to 10MB for example)
610
  file.seek(0, 2) # Seek to end
611
  file_size = file.tell()
612
  file.seek(0) # Reset to beginning
613
 
614
- if file_size > 10 * 1024 * 1024: # 10MB limit
615
- return jsonify({'success': False, 'error': 'File too large. Maximum size is 10MB.'})
616
 
617
  # Read file content
618
  file_content = file.read()
@@ -716,8 +726,8 @@ def upload_from_url():
716
 
717
  # Check file size
718
  content_length = len(response.content)
719
- if content_length > 10 * 1024 * 1024: # 10MB limit
720
- return jsonify({'success': False, 'error': 'File too large. Maximum size is 10MB.'})
721
 
722
  file_io = io.BytesIO(response.content)
723
 
@@ -896,7 +906,7 @@ def health_check():
896
  # Error handlers
897
  @app.errorhandler(413)
898
  def too_large(e):
899
- return jsonify({'success': False, 'error': 'File too large'}), 413
900
 
901
  @app.errorhandler(500)
902
  def internal_error(e):
 
21
  app = Flask(__name__)
22
  CORS(app)
23
 
24
+ # Configure Flask for larger file uploads
25
+ app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024 # 50MB max file size
26
+
27
  # Initialize Gemini client with correct API key
28
  client = genai.Client(api_key=GOOGLE_API_KEY)
29
 
 
344
  <div class="upload-area" id="uploadArea">
345
  <div class="upload-icon">πŸ“„</div>
346
  <p>Drag and drop your PDF file here, or click to select</p>
347
+ <p style="font-size: 0.9em; color: #666; margin-top: 10px;">Maximum file size: 50MB</p>
348
  <input type="file" id="fileInput" class="file-input" accept=".pdf">
349
  <button class="upload-btn" onclick="document.getElementById('fileInput').click()">
350
  Choose PDF File
 
431
  return;
432
  }
433
 
434
+ // Check file size on client side (50MB limit)
435
+ if (file.size > 50 * 1024 * 1024) {
436
+ showError('File too large. Maximum size is 50MB.');
437
+ return;
438
+ }
439
+
440
  showLoading('Uploading PDF...');
441
 
442
  const formData = new FormData();
 
616
  if file.filename == '':
617
  return jsonify({'success': False, 'error': 'No file selected'})
618
 
619
+ # Check file size (limit to 50MB for PDFs)
620
  file.seek(0, 2) # Seek to end
621
  file_size = file.tell()
622
  file.seek(0) # Reset to beginning
623
 
624
+ if file_size > 50 * 1024 * 1024: # 50MB limit
625
+ return jsonify({'success': False, 'error': 'File too large. Maximum size is 50MB.'})
626
 
627
  # Read file content
628
  file_content = file.read()
 
726
 
727
  # Check file size
728
  content_length = len(response.content)
729
+ if content_length > 50 * 1024 * 1024: # 50MB limit
730
+ return jsonify({'success': False, 'error': 'File too large. Maximum size is 50MB.'})
731
 
732
  file_io = io.BytesIO(response.content)
733
 
 
906
  # Error handlers
907
  @app.errorhandler(413)
908
  def too_large(e):
909
+ return jsonify({'success': False, 'error': 'File too large. Maximum size is 50MB.'}), 413
910
 
911
  @app.errorhandler(500)
912
  def internal_error(e):