Jagukumar commited on
Commit
a3f606f
·
verified ·
1 Parent(s): 4faa324

Upload 2 files

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