rairo commited on
Commit
10b6805
·
verified ·
1 Parent(s): 7dd4394

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -16
main.py CHANGED
@@ -378,30 +378,19 @@ def process_image():
378
  try:
379
  model = configure_gemini(api_key)
380
 
381
- # Upload image file to Gemini
382
- logging.info(f"Uploading image file: {file.filename}")
383
- uploaded_file = genai.upload_file(file_path)
384
 
385
- # Wait for file to be processed
386
- while uploaded_file.state.name == "PROCESSING":
387
- time.sleep(1)
388
- uploaded_file = genai.get_file(uploaded_file.name)
389
-
390
- if uploaded_file.state.name == "FAILED":
391
- raise ValueError("Image processing failed")
392
-
393
- logging.info("Processing image for transaction extraction")
394
 
395
  # Generate content with the image and prompt
396
- response = model.generate_content([uploaded_file, PROMPT])
397
 
398
  # Parse the response
399
  result = extract_json_from_response(response.text)
400
  transactions = result.get('transactions', [])
401
 
402
- # Clean up the uploaded file from Gemini
403
- genai.delete_file(uploaded_file.name)
404
-
405
  return jsonify({'transactions': transactions})
406
 
407
  finally:
 
378
  try:
379
  model = configure_gemini(api_key)
380
 
381
+ logging.info(f"Processing image file: {file.filename}")
 
 
382
 
383
+ # Read image file as bytes
384
+ import PIL.Image
385
+ img = PIL.Image.open(file_path)
 
 
 
 
 
 
386
 
387
  # Generate content with the image and prompt
388
+ response = model.generate_content([PROMPT, img])
389
 
390
  # Parse the response
391
  result = extract_json_from_response(response.text)
392
  transactions = result.get('transactions', [])
393
 
 
 
 
394
  return jsonify({'transactions': transactions})
395
 
396
  finally: