ByteBrewer commited on
Commit
c28fd42
·
verified ·
1 Parent(s): 6c400fe

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +58 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import google.generativeai as genai
4
+ from PIL import Image
5
+
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
+
9
+ # Configuring the google api key...
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+ # Function to load Gemini-pro-vision model...
13
+ model = genai.GenerativeModel("gemini-pro-vision")
14
+
15
+ def get_gemini_response(input,image, prompt):
16
+ response = model.generate_content([input, image[0], prompt])
17
+ return response.text
18
+
19
+ def input_image_setup(uploaded_file):
20
+ # Check if a file has been uploaded
21
+ if uploaded_file is not None:
22
+ # Read the file into bytes
23
+ bytes_data = uploaded_file.getvalue()
24
+ image_parts = [
25
+ {
26
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
27
+ "data": bytes_data
28
+ }
29
+ ]
30
+ return image_parts
31
+ else:
32
+ raise FileNotFoundError("No file uploaded")
33
+
34
+
35
+
36
+ ##initialize our streamlit app
37
+ st.set_page_config(page_title="Extract your invoice")
38
+ st.header("Extract your invoice")
39
+ input=st.text_input("Input Prompt: ",key="input")
40
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
41
+ image = ""
42
+ if uploaded_file is not None:
43
+ image = Image.open(uploaded_file)
44
+ st.image(image, caption="!!!...Uploaded Invoice...!!!", use_column_width=True)
45
+
46
+ submit = st.button("Tell me about the prompt")
47
+
48
+ input_prompt = """
49
+ You are an expert in understanding invoices.
50
+ You will receive input images as invoices &
51
+ you will have to answer questions based on the uploaded invoice input image
52
+ """
53
+
54
+ if submit:
55
+ image_data = input_image_setup(uploaded_file)
56
+ response=get_gemini_response(input_prompt,image_data,input)
57
+ st.subheader("The Response is")
58
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb
7
+ faiss-cpu