Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,64 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from dotenv import load_dotenv
|
3 |
-
|
4 |
-
load_dotenv() ## load all env vriables from .env
|
5 |
-
|
6 |
-
import os
|
7 |
-
|
8 |
-
from PIL import Image
|
9 |
-
|
10 |
-
|
11 |
-
genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))
|
12 |
-
|
13 |
-
# create a function to load gemini pro vision
|
14 |
-
model = genai.
|
15 |
-
|
16 |
-
def get_gemini_response(input,image,prompt):
|
17 |
-
response = model.generate_content([input,image[0],prompt])
|
18 |
-
return response.text
|
19 |
-
|
20 |
-
## create a function to return images bayets data
|
21 |
-
|
22 |
-
def input_image_details(uploaded_file):
|
23 |
-
if uploaded_file is not None :
|
24 |
-
# read the file into a bytes
|
25 |
-
bytes_data = uploaded_file.getvalue()
|
26 |
-
|
27 |
-
image_parts = [
|
28 |
-
{
|
29 |
-
"mime_type" : uploaded_file.type, # get the mime type of the uploaded file
|
30 |
-
"data" : bytes_data
|
31 |
-
}
|
32 |
-
]
|
33 |
-
return image_parts
|
34 |
-
else :
|
35 |
-
raise FileNotFoundError('No file uploaded')
|
36 |
-
|
37 |
-
## initialize our streamlit app
|
38 |
-
|
39 |
-
st.set_page_config(page_title = 'MultiLanguage Invoice Extractor')
|
40 |
-
st.header("Gemini Application")
|
41 |
-
|
42 |
-
input = st.text_input('Input Prompt: ',key = 'input')
|
43 |
-
uploaded_file = st.file_uploader('Choose an image of the Invoice',type = ["jpg",'jpeg','png'])
|
44 |
-
|
45 |
-
if uploaded_file is not None :
|
46 |
-
image = Image.open(uploaded_file)
|
47 |
-
st.image(image,caption='Uploaded Image', use_colume_width = True)
|
48 |
-
|
49 |
-
submit = st.button("Tell me about the invoice")
|
50 |
-
|
51 |
-
input_prompt = """
|
52 |
-
you are a expert in understaning invoices. we will upload an image as invoice
|
53 |
-
and you will have to answer any questions based on the uploaded invoice image
|
54 |
-
"""
|
55 |
-
|
56 |
-
# if submit button is clicked
|
57 |
-
|
58 |
-
if
|
59 |
-
image_data = input_image_details(uploaded_file)
|
60 |
-
response = get_gemini_response(input_prompt,image_data,input)
|
61 |
-
st.subheader("The Response is ")
|
62 |
-
st.write(response)
|
63 |
-
|
64 |
-
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
|
4 |
+
load_dotenv() ## load all env vriables from .env
|
5 |
+
|
6 |
+
import os
|
7 |
+
|
8 |
+
from PIL import Image
|
9 |
+
import google.generativeai as genai
|
10 |
+
|
11 |
+
genai.configure(api_key = os.getenv('GOOGLE_API_KEY'))
|
12 |
+
|
13 |
+
# create a function to load gemini pro vision
|
14 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
15 |
+
|
16 |
+
def get_gemini_response(input,image,prompt):
|
17 |
+
response = model.generate_content([input,image[0],prompt])
|
18 |
+
return response.text
|
19 |
+
|
20 |
+
## create a function to return images bayets data
|
21 |
+
|
22 |
+
def input_image_details(uploaded_file):
|
23 |
+
if uploaded_file is not None :
|
24 |
+
# read the file into a bytes
|
25 |
+
bytes_data = uploaded_file.getvalue()
|
26 |
+
|
27 |
+
image_parts = [
|
28 |
+
{
|
29 |
+
"mime_type" : uploaded_file.type, # get the mime type of the uploaded file
|
30 |
+
"data" : bytes_data
|
31 |
+
}
|
32 |
+
]
|
33 |
+
return image_parts
|
34 |
+
else :
|
35 |
+
raise FileNotFoundError('No file uploaded')
|
36 |
+
|
37 |
+
## initialize our streamlit app
|
38 |
+
|
39 |
+
st.set_page_config(page_title = 'MultiLanguage Invoice Extractor')
|
40 |
+
st.header("Gemini Application")
|
41 |
+
|
42 |
+
input = st.text_input('Input Prompt: ',key = 'input')
|
43 |
+
uploaded_file = st.file_uploader('Choose an image of the Invoice',type = ["jpg",'jpeg','png'])
|
44 |
+
|
45 |
+
if uploaded_file is not None :
|
46 |
+
image = Image.open(uploaded_file)
|
47 |
+
st.image(image,caption='Uploaded Image', use_colume_width = True)
|
48 |
+
|
49 |
+
submit = st.button("Tell me about the invoice")
|
50 |
+
|
51 |
+
input_prompt = """
|
52 |
+
you are a expert in understaning invoices. we will upload an image as invoice
|
53 |
+
and you will have to answer any questions based on the uploaded invoice image
|
54 |
+
"""
|
55 |
+
|
56 |
+
# if submit button is clicked
|
57 |
+
|
58 |
+
if submit :
|
59 |
+
image_data = input_image_details(uploaded_file)
|
60 |
+
response = get_gemini_response(input_prompt,image_data,input)
|
61 |
+
st.subheader("The Response is ")
|
62 |
+
st.write(response)
|
63 |
+
|
64 |
+
|