File size: 781 Bytes
eae6922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3b93e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import google.generativeai as genai
from PIL import Image
import os

os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])

class Model:
    def __init__(self) -> None:
        self.model = genai.GenerativeModel('gemini-1.5-flash-latest')
        
    def get_response(self, image):
        prompt = """You are an intelligent document creator. Could you please extract the words from the given screenshot and provide me document text that matches exact screenshot font and look
        important note: if the screenshot not contain any text means you must say 'please upload a valid screenshot.'"""
        img = Image.open(image)
        response = self.model.generate_content([prompt, img]) 
        return response.text