lisaf commited on
Commit
ed613b8
1 Parent(s): 522ff0a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +107 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import streamlit as st
3
+ import os
4
+ from PIL import Image
5
+ import google.generativeai as genai
6
+
7
+ # Configure Google API key from environment variables
8
+ load_dotenv()
9
+ genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
10
+
11
+ # Initialize the Generative Model
12
+ model = genai.GenerativeModel('gemini-pro-vision')
13
+
14
+ # Function to get Gemini response
15
+ def get_gemini_response(input, image, prompt):
16
+ response = model.generate_content([input, image[0], prompt])
17
+ return response.text
18
+
19
+ # Function to extract image details
20
+ def input_image_details(uploaded_file):
21
+ if uploaded_file is not None:
22
+ bytes_data = uploaded_file.getvalue()
23
+ image_parts = [{
24
+ "mime_type": uploaded_file.type,
25
+ "data": bytes_data
26
+ }]
27
+ return image_parts
28
+ else:
29
+ raise FileNotFoundError("No file uploaded")
30
+
31
+ # Set page title and description
32
+ st.set_page_config(
33
+ page_title='Invoice AI Assistant',
34
+ page_icon=':money_with_wings:',
35
+ layout='wide',
36
+ initial_sidebar_state='collapsed'
37
+ )
38
+
39
+ # Page title and description
40
+ st.title('Welcome to Invoice AI Assistant!')
41
+ st.markdown('This app helps you analyze invoices using AI.')
42
+
43
+ # Input prompt textbox
44
+ input_prompt = st.text_input("Input prompt:", key="input")
45
+
46
+ # Apply CSS style to text input
47
+ st.markdown('<style>input[type="text"] {color: black;}</style>', unsafe_allow_html=True)
48
+
49
+ # File uploader for image selection
50
+ uploaded_file = st.file_uploader("Choose an image of the invoice", type=["jpg", "jpeg", "png"])
51
+ 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
+ # Button to trigger invoice analysis
57
+ submit = st.button("Analyze Invoice")
58
+
59
+ # Perform analysis on button click
60
+ if submit:
61
+ # Extract image details
62
+ image_data = input_image_details(uploaded_file)
63
+ # Get response from Gemini model
64
+ response = get_gemini_response(input_prompt, image_data, input_prompt)
65
+ # Display response
66
+ st.subheader("The Response For Your Query is")
67
+ st.write(response)
68
+
69
+ # UI enhancements
70
+ st.markdown(
71
+ """
72
+ <style>
73
+ .reportview-container {
74
+ background: linear-gradient(to bottom, #f2f2f2, #ffffff);
75
+ }
76
+ .sidebar .sidebar-content {
77
+ background: linear-gradient(to bottom, #f2f2f2, #ffffff);
78
+ }
79
+ .st-bk {
80
+ background-color: #ffffff;
81
+ }
82
+ .st-c5 {
83
+ color: #1b2d6b;
84
+ }
85
+ .stButton>button {
86
+ background-color: #1b2d6b !important;
87
+ color: white !important;
88
+ font-weight: bold;
89
+ border-radius: 5px;
90
+ }
91
+ .stButton>button:hover {
92
+ background-color: #0056b3 !important;
93
+ }
94
+ .stTextInput>div>div>input {
95
+ border-color: #1b2d6b !important;
96
+ }
97
+ .stTextInput>div>div>input:focus {
98
+ box-shadow: 0 0 0 0.2rem rgba(27, 45, 107, 0.25) !important;
99
+ border-color: #1b2d6b !important;
100
+ }
101
+ .stMarkdown a {
102
+ color: #1b2d6b !important;
103
+ }
104
+ </style>
105
+ """,
106
+ unsafe_allow_html=True
107
+ )
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb