arnabbumba077 commited on
Commit
bfeb081
·
verified ·
1 Parent(s): 362e8c5

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +58 -0
  3. requirements.txt +6 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY="AIzaSyAJjp2hRJBGsei-o6kfvnZ8EeKkXl4-XuI"
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv() ## load all the environment variables from .env
4
+
5
+ import streamlit as st
6
+ import os
7
+ from PIL import Image
8
+ import google.generativeai as genai
9
+
10
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
11
+
12
+ ## Function to load Gemini Pro Vision
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_details(uploaded_file):
20
+ if uploaded_file is not None:
21
+ # Read the file into bytes
22
+ bytes_data=uploaded_file.getvalue()
23
+
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
+ ## Initialize our streamlit app
35
+
36
+ st.set_page_config(page_title="MultiLanguage Invoice Extractor")
37
+
38
+ st.header("MultiLanguage Invoice Extractor")
39
+ input=st.text_input("Input Prompt: ",key="input")
40
+ uploaded_file=st.file_uploader("Choose an image of the invoice...", 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 Image.", use_column_width=True)
45
+
46
+ submit=st.button("Tell me about the invoice")
47
+
48
+ input_prompt="""
49
+ You are an expert in understanding invoices. We will upload an image as invoice and you will have to answer any questions based on the uploaded invoice image.
50
+ """
51
+
52
+ # If submit button is clicked
53
+
54
+ if submit:
55
+ image_data=input_image_details(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,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb