yashjainme commited on
Commit
090f783
·
verified ·
1 Parent(s): 5d2a637

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv() # load all the environment variables from .env
4
+
5
+
6
+ import streamlit as st
7
+ import os
8
+ from PIL import Image
9
+ import google.generativeai as genai
10
+
11
+ genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
12
+
13
+
14
+ # function to load gemini pro vision
15
+
16
+
17
+ def get_response(model, input, image, prompt):
18
+ response = model.generate_content([input, image[0], prompt])
19
+
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,
31
+ "data": bytes_data
32
+ }
33
+ ]
34
+ return image_parts
35
+ else:
36
+ raise FileNotFoundError("No file uploaded")
37
+
38
+
39
+
40
+ # Initialize streamlit
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
+
47
+ image = ''
48
+ if uploaded_file is not None:
49
+ image = Image.open(uploaded_file)
50
+ st.image(image, caption='Uploaded image', use_column_width=True)
51
+
52
+ submit = st.button("Tell me about the invoice")
53
+
54
+
55
+ input_prompt = """
56
+ You are a skilled professional specializing in the interpretation of invoices across various languages. Users will upload images of invoices, and you will provide accurate responses to any questions related specifically to invoices. Your task is to offer precise and insightful assistance in invoice interpretation, ensuring clarity, structured and accuracy in your responses.
57
+
58
+ """
59
+ if submit:
60
+ model = genai.GenerativeModel('gemini-1.5-flash')
61
+ image_data = input_image_details(uploaded_file)
62
+ response = get_response(model, input_prompt, image_data, input)
63
+ st.subheader('The Resposne is')
64
+ st.write(response)
65
+
66
+