Nechba commited on
Commit
a1ae797
·
verified ·
1 Parent(s): 3a55e0a

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +12 -0
utils.py CHANGED
@@ -1,4 +1,5 @@
1
  import google.generativeai as genai
 
2
  import os
3
  import pandas as pd
4
  import io
@@ -6,11 +7,22 @@ import tempfile
6
  from PyPDF2 import PdfReader
7
  import re
8
  import csv
 
 
9
 
10
  def configure_gemini(api_key: str):
11
  """Configure Gemini API with the provided key"""
12
  genai.configure(api_key=api_key)
13
 
 
 
 
 
 
 
 
 
 
14
  def analyze_pdf_directly(pdf_bytes: bytes, prompt: str, model_name: str = "gemini-1.5-pro"):
15
  """Analyze a PDF directly using Gemini's PDF support"""
16
  model = genai.GenerativeModel(model_name)
 
1
  import google.generativeai as genai
2
+ genai.configure(api_key="AIzaSyAP85jSUKncrIGOAhm3Gvo-TYra_e1wmEA")
3
  import os
4
  import pandas as pd
5
  import io
 
7
  from PyPDF2 import PdfReader
8
  import re
9
  import csv
10
+ from PIL import Image
11
+ from pdf2image import convert_from_bytes
12
 
13
  def configure_gemini(api_key: str):
14
  """Configure Gemini API with the provided key"""
15
  genai.configure(api_key=api_key)
16
 
17
+ def pdf_to_images(pdf_bytes: bytes) -> list:
18
+ """Convert PDF bytes to list of PIL Images"""
19
+ return convert_from_bytes(pdf_bytes)
20
+
21
+ def analyze_single_document(images: list, prompt: str) -> dict:
22
+ """Analyze a single document and return results"""
23
+ model = genai.GenerativeModel('gemini-2.0-flash-thinking-exp-01-21')
24
+ response = model.generate_content([prompt] + images)
25
+ return response.text
26
  def analyze_pdf_directly(pdf_bytes: bytes, prompt: str, model_name: str = "gemini-1.5-pro"):
27
  """Analyze a PDF directly using Gemini's PDF support"""
28
  model = genai.GenerativeModel(model_name)