souvikmaji22 commited on
Commit
74cee35
1 Parent(s): ba9d781

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import google.generativeai as genai
5
+ import streamlit as st
6
+ import os
7
+ from PIL import Image
8
+
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+
11
+ model=genai.GenerativeModel('gemini-pro-vision')
12
+
13
+ def get_res(input,image,prompt):
14
+ res=model.generate_content([input,image[0],prompt])
15
+ return res.text
16
+
17
+ def input_image_setup(uploaded_file):
18
+ if uploaded_file is not None:
19
+ bytes_data=uploaded_file.getvalue()
20
+ image_parts =[
21
+ {
22
+ "mime_type": uploaded_file.type,
23
+ "data": bytes_data
24
+ }
25
+ ]
26
+ return image_parts
27
+ else:
28
+ raise FileNotFoundError("No File Uploaded")
29
+
30
+
31
+ #streamlit
32
+
33
+ st.set_page_config("Multi-Language Invoice Extractor")
34
+ st.header("Multi-Language Invoice Extractor")
35
+ input=st.text_input("Input: ", key="input")
36
+ file = st.file_uploader("Choose an Image of the Invoice", type=["jpg","jpeg","png"])
37
+
38
+ image=""
39
+ if file is not None:
40
+ image=Image.open(file)
41
+ st.image(image, caption="Uploaded Image: ", use_column_width=True)
42
+
43
+ submit=st.button("Tell me")
44
+
45
+ input_prompt="""
46
+ ou are an expert in invoice analysis. I will upload an invoice image, and you need to answer any questions I ask based on the details in the image.
47
+ """
48
+
49
+ if submit:
50
+ image_data= input_image_setup(file)
51
+ res = get_res(input_prompt,image_data,input)
52
+ st.subheader("Response: ")
53
+ st.write(res)