Omartificial-Intelligence-Space commited on
Commit
1ed7d4b
·
verified ·
1 Parent(s): c0dd202

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -662,9 +662,20 @@ def upload_file():
662
 
663
  # Upload to Gemini File API
664
  try:
665
- # Simple file upload - no config parameter needed
666
- document = client.files.upload(file=file_io)
 
 
 
 
 
 
667
  print(f"Document uploaded successfully: {document.name}")
 
 
 
 
 
668
  except Exception as upload_error:
669
  print(f"Upload error: {upload_error}")
670
  return jsonify({'success': False, 'error': f'Failed to upload file to Gemini: {str(upload_error)}'})
@@ -815,9 +826,21 @@ def upload_from_url():
815
 
816
  # Upload to Gemini File API
817
  try:
818
- # Simple file upload - no config parameter needed
819
- document = client.files.upload(file=file_io)
 
 
 
 
 
 
 
 
820
  print(f"Document uploaded successfully: {document.name}")
 
 
 
 
821
  except Exception as upload_error:
822
  print(f"Upload error: {upload_error}")
823
  return jsonify({'success': False, 'error': f'Failed to upload file to Gemini: {str(upload_error)}'})
 
662
 
663
  # Upload to Gemini File API
664
  try:
665
+ # Save the BytesIO to a temporary file since the API expects a file path
666
+ import tempfile
667
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file:
668
+ temp_file.write(file_content)
669
+ temp_file_path = temp_file.name
670
+
671
+ # Upload using file path
672
+ document = client.files.upload(path=temp_file_path)
673
  print(f"Document uploaded successfully: {document.name}")
674
+
675
+ # Clean up temporary file
676
+ import os
677
+ os.unlink(temp_file_path)
678
+
679
  except Exception as upload_error:
680
  print(f"Upload error: {upload_error}")
681
  return jsonify({'success': False, 'error': f'Failed to upload file to Gemini: {str(upload_error)}'})
 
826
 
827
  # Upload to Gemini File API
828
  try:
829
+ # Save the BytesIO to a temporary file since the API expects a file path
830
+ import tempfile
831
+ import os
832
+
833
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file:
834
+ temp_file.write(response.content)
835
+ temp_file_path = temp_file.name
836
+
837
+ # Upload using file path
838
+ document = client.files.upload(path=temp_file_path)
839
  print(f"Document uploaded successfully: {document.name}")
840
+
841
+ # Clean up temporary file
842
+ os.unlink(temp_file_path)
843
+
844
  except Exception as upload_error:
845
  print(f"Upload error: {upload_error}")
846
  return jsonify({'success': False, 'error': f'Failed to upload file to Gemini: {str(upload_error)}'})