Dipesh17 commited on
Commit
75c40b7
1 Parent(s): 9b621c3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +70 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Importing required librabies
2
+ from dotenv import load_dotenv
3
+ import streamlit as st
4
+ import os
5
+ from PIL import Image
6
+ import google.generativeai as genai
7
+
8
+
9
+ # Loading all the environment variables from .env
10
+ load_dotenv()
11
+
12
+
13
+ # Loading Gemini Pro Vision model
14
+ genai.configure(api_key="AIzaSyB8iSqVbUcsOQLi--ghQpCnoyLj2ArDoII")
15
+ model = genai.GenerativeModel('gemini-pro-vision')
16
+
17
+
18
+ # Function to generate response for query using Gemini Pro Vision
19
+ def get_gemini_response(input, image, prompt):
20
+ response = model.generate_content([input, image[0], prompt])
21
+ return response.text
22
+
23
+
24
+ # Funtion to preprocess image
25
+ def input_image_details(uploaded_file):
26
+ if uploaded_file is not None:
27
+ bytes_data = uploaded_file.getvalue()
28
+ iamge_parts = [
29
+ {
30
+ 'mime_type' : uploaded_file.type,
31
+ 'data' : bytes_data
32
+ }
33
+ ]
34
+ return iamge_parts
35
+ else:
36
+ raise FileNotFoundError("No file uploaded")
37
+
38
+
39
+
40
+ # Initialize streamlit app
41
+
42
+ # Title
43
+ st.set_page_config(page_title="MultiLanguage Invoice Extractor")
44
+ st.header("MultiLanguage Invoice Extractor")
45
+
46
+ # Inputs
47
+ input = st.text_input("Input Prompt: ", key='input')
48
+ uploaded_file = st.file_uploader("Choose an image of the invoice...",type=['jpg', 'jpeg', 'png', ])
49
+ image = ""
50
+
51
+ # Display the image
52
+ if uploaded_file is not None:
53
+ image = Image.open(uploaded_file)
54
+ st.image(image, caption='Uploaded Image', use_column_width=True)
55
+
56
+ # Creating submit button
57
+ submit = st.button("Tell me about the invoice")
58
+
59
+ # Prompt
60
+ input_prompt = """
61
+ You are an expert in understanding invoices. We will upload a image invoice and
62
+ you will have to answer any questions based on the uploaded invoice image
63
+ """
64
+
65
+ # If submit button is clicked... (Calling the function to generate response)
66
+ if submit:
67
+ image_data = input_image_details(uploaded_file)
68
+ response = get_gemini_response(input_prompt, image_data, input)
69
+ st.subheader("The Response is")
70
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb