-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinnvoicesprocessig.py
More file actions
40 lines (33 loc) · 2.74 KB
/
innvoicesprocessig.py
File metadata and controls
40 lines (33 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#x = [<invoice no.> , <invoice total amount> , <invoice date> , <invoice description> , <invoice file path> , <no. of types of products>, <Total IGST value> , <SUB total>, {<porduct1>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , <porduct1>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , <porduct2>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , <porduct3>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , .....}]
import PIL.Image
import geminiapikey
import google.generativeai as genai
import PIL
import os
def upload_to_gemini(path, mime_type=None):
file = genai.upload_file(path, mime_type=mime_type)
print(f"Uploaded file '{file.display_name}' as: {file.uri}")
return file
gemini_api_key = geminiapikey.access_api_key()
genai.configure(api_key=gemini_api_key)
generation_config = {
"temperature": 0,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-pro",
generation_config=generation_config,
)
image_path = input("Enter the image path: ")
if not os.path.isfile(image_path):
raise SystemExit("Invalid Image path! Exiting....")
img = PIL.Image.open(image_path)
response = model.generate_content([img , "You are an employee of a water filtration systems distributor. Your task is to take an image of an invoice form the user and scan out details like invoice no. ,invoice total amount , invoice date , invoice description , invoice file path , no. of types of products, Total IGST value , SUB total, different products with their subsequent details in a variable in python in the following way \n[<invoice no.> , <invoice total amount> , <invoice date> , <invoice file path> , <no. of types of products>, <Total IGST value> , <SUB total>, {<porduct1>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , <porduct1>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , <porduct2>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , <porduct3>:[<description> , <IGST%> , <IGST Value> , <Quantity> , <Price INR> , <taxable Value INR>] , .....}]\nnote that ..... represents the other products listed in the invoice. If an value is not found fill it with None value. Give output like this example: ['7024000606',42338.37,'19/06/24',None,1,6458.40,35879.97,{'IA290100303': ['IAS102T',18,6458.40,2.00,17417.460,34834.92]}] and in text block"])
print(response.text)
# temp = response.text.split("\n")
# print(temp)
# image_data = eval(temp[0])
# print(image_data)