nasirkhan786 commited on
Commit
b72363d
·
0 Parent(s):
Files changed (6) hide show
  1. .gitignore +1 -0
  2. Readme.md +11 -0
  3. app.py +60 -0
  4. poetry.lock +0 -0
  5. pyproject.toml +19 -0
  6. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
Readme.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Invoice Extractor Using Gemini
3
+ emoji: 📈
4
+ colorFrom: yellow
5
+ colorTo: purple
6
+ sdk: streamlit
7
+ sdk_version: 1.39.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import google.generativeai as genai # type: ignore
3
+ import streamlit as st
4
+ from dotenv import load_dotenv
5
+ import os
6
+ load_dotenv()
7
+
8
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
9
+
10
+ # load gemini pro vision
11
+ model = genai.GenerativeModel("gemini-1.5-flash")
12
+
13
+ def input_image_details(upload_file):
14
+ if upload_file is not None:
15
+ # read the file into bytes
16
+ bytes_data= upload_file.getvalue()
17
+
18
+ image_parts = [
19
+ {
20
+ "mime_type":upload_file.type,
21
+ "data":bytes_data
22
+ }
23
+
24
+ ]
25
+ return image_parts
26
+ else:
27
+ raise FileNotFoundError("No file uploaded")
28
+
29
+
30
+ def get_gemni_response(prompt, image,user_input):
31
+ response = model.generate_content([prompt, image[0], user_input])
32
+ return response.text
33
+
34
+
35
+ #initilize our streamlite app
36
+ st.set_page_config(page_title="Multilanguage Invoice Extractor ")
37
+ st.header("MultiLanguage Invoice Extractor")
38
+ user_input = st.text_input("Input Prompt", key="input")
39
+ upload_file = st.file_uploader("choose an image of the invoice..", type=["jpg","jpeg","png"])
40
+
41
+ # to show the uploaded image
42
+ if upload_file is not None:
43
+ image = Image.open(upload_file)
44
+ st.image(image, caption="upload Image.", use_column_width=True)
45
+
46
+
47
+ submit = st.button("Tell me about the Invice")
48
+
49
+ prompt = """
50
+ Your are an expert in understanding invoice. We will upload a image as invoice
51
+ and you will have to answer any questions based on the upload invoice image
52
+ """
53
+
54
+
55
+ # if submit buttion is clicked
56
+ if submit:
57
+ image_data = input_image_details(upload_file)
58
+ response = get_gemni_response(prompt, image_data, user_input)
59
+ st.subheader("The response is")
60
+ st.write(response)
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "invoice extractor llm app using google gemini pro vision large image models"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["Nasir Abbas <akhtarabbas.islamicreaction@gmail.com>"]
6
+ readme = "README.md"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "^3.12"
10
+ streamlit = "^1.39.0"
11
+ python-dotenv = "^1.0.1"
12
+ pypdf2 = "^3.0.1"
13
+ google-generativeai = "^0.8.3"
14
+
15
+
16
+
17
+ [build-system]
18
+ requires = ["poetry-core"]
19
+ build-backend = "poetry.core.masonry.api"
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ python-dotenv
3
+ google-generativeai