rakeshkumar1812 commited on
Commit
cd9864e
·
verified ·
1 Parent(s): 9e34cdd

Upload 2 files

Browse files

two files uploaded

Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Invoice Extractor..
2
+
3
+ from dotenv import load_dotenv
4
+ load_dotenv() ## load all environment variables into the project
5
+ import streamlit as st
6
+ import os
7
+ from PIL import Image
8
+ import google.generativeai as genai
9
+
10
+ ## Configuring API key
11
+ genai.configure(api_key = os.getenv("GOOGLE_API_KEY"))
12
+
13
+
14
+ ## Function to load Gemini Pro Vision Model and get Response
15
+ def get_gemini_response(input, image, prompt):
16
+ # Loading the Gemini Model
17
+ model = genai.GenerativeModel('gemini-pro-vision')
18
+ response = model.generate_content([input, image[0], prompt])
19
+
20
+ return response.text
21
+
22
+
23
+ def input_image_setup(uploaded_file):
24
+ if uploaded_file is not None:
25
+ # read the file into bytes
26
+ bytes_data = uploaded_file.getvalue()
27
+ image_part = [{
28
+ "mime_type": uploaded_file.type,
29
+ "data": bytes_data
30
+ }]
31
+ return image_part
32
+ else:
33
+ raise FileNotFoundError("No File Uploaded...")
34
+
35
+
36
+ # Initialize our streamlit app
37
+ st.set_page_config(page_title= "Invoice Extractor")
38
+
39
+ st.header("Gemini Application")
40
+ input = st.text_input("Input Prompt: ", key = "input")
41
+ uploaded_file= st.file_uploader("Choose an Image....", type=["jpg", "jpeg", "png"])
42
+ image = ""
43
+ if uploaded_file is not None:
44
+ image = Image.open(uploaded_file)
45
+ st.image(image, caption="Uploaded Image", use_column_width=True)
46
+
47
+
48
+
49
+ submit = st.button('Tell Me about the Invoice')
50
+
51
+ input_prompt = """
52
+ you are an expert in understanding invoices.
53
+ you will receive input images as invoices and you will
54
+ have to answer questions based on the input image.
55
+ """
56
+ ## If Submit button is clicked...
57
+
58
+ if submit:
59
+ image_data = input_image_setup(uploaded_file)
60
+ response = get_gemini_response(input_prompt, image_data, input)
61
+
62
+ st.subheader("The Response is :")
63
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google-generativeai
2
+ streamlit
3
+ python-dotenv