VarsaGupta commited on
Commit
af4b597
·
verified ·
1 Parent(s): d2100e0

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### CELLSTRAT HUB PACK - LANGCHAIN05
2
+
3
+ ### This Streamlit web application, titled "MultiLanguage Invoice Extractor," leverages Google's Generative AI Gemini Pro Vision model to analyze and extract data from uploaded invoice images. It begins by setting up the environment and importing necessary libraries, including Streamlit for the web interface and Google's Generative AI library. Users can upload an invoice image in various formats, which is then displayed on the screen. The app allows users to input a prompt regarding the invoice, and upon submission, it processes this input alongside the image data through the Gemini Pro Vision model. The app then displays the AI-generated insights or information extracted from the invoice, making it a practical tool for understanding and processing invoice data in multiple languages.
4
+
5
+
6
+ from dotenv import load_dotenv
7
+ load_dotenv() ##load all the environment variables from .env
8
+
9
+ import streamlit as st
10
+ import os
11
+ from PIL import Image
12
+ import google.generativeai as genai
13
+
14
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
+
16
+ ### Function to load Gemini Pro Vision
17
+ model= genai.GenerativeModel('gemini-pro-vision')
18
+ def get_gemini_response(input,image,prompt):
19
+ response = model.generate_content([input,image[0],prompt])
20
+ return response.text
21
+
22
+
23
+ def input_image_details(uploaded_file):
24
+ if uploaded_file is not None:
25
+ #Read the file into bytes
26
+ bytes_data= uploaded_file.getvalue()
27
+
28
+ image_parts=[
29
+ {
30
+ "mime_type": uploaded_file.type, #Get the mmime type of the uploaded file
31
+ "data":bytes_data
32
+ }
33
+ ]
34
+ return image_parts
35
+ else:
36
+ raise FileNotFoundError("No file uploaded")
37
+
38
+
39
+ ###initialize our streamlit app
40
+
41
+ st.set_page_config(page_title="MultiLanguage Invoice Extractor")
42
+
43
+ st.header("MultiLanguage Invoice Extractor")
44
+ input=st.text_input("Input Prompt: ",key="input")
45
+ uploaded_file=st.file_uploader("Choose an image of the invoice....",type=["jpg","jpeg","png"])
46
+ image=""
47
+ if uploaded_file is not None:
48
+ image = Image.open(uploaded_file)
49
+ st.image(image,caption="Uploaded Image",use_column_width=True)
50
+
51
+ submit=st.button("Tell me about the invoice")
52
+ input_prompt="""
53
+ You are an expert in understanding invoices. We will upload an image as invoice and you will have to answer any question based on the uploaded invoice image
54
+ """
55
+
56
+ ## If submit button is clicked
57
+ if submit:
58
+ image_data = input_image_details(uploaded_file)
59
+ response= get_gemini_response(input_prompt,image_data,input)
60
+ st.subheader("The Response is")
61
+ st.write(response)
62
+
63
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb