1Prarthana commited on
Commit
c5c4061
Β·
verified Β·
1 Parent(s): 419ff59

Upload 4 files

Browse files
Files changed (5) hide show
  1. .env +1 -0
  2. .gitattributes +1 -0
  3. img.png +3 -0
  4. requirements.txt +7 -0
  5. vision.py +234 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY = "AIzaSyCuh8F92Mm3UCoFLg74tugLQdPOo_yA4i0"
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ img.png filter=lfs diff=lfs merge=lfs -text
img.png ADDED

Git LFS Details

  • SHA256: 8493d2ac25e7766453f31bbf0f5384894bbafe223ae1ca645d4ea46a9f0aa653
  • Pointer size: 131 Bytes
  • Size of remote file: 292 kB
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb
7
+ faiss-cpu
vision.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # # Import libraries
3
+ # from dotenv import load_dotenv
4
+ # import streamlit as st
5
+ # import os
6
+ # from PIL import Image
7
+ # import google.generativeai as genai
8
+ #
9
+ # # Load environment variables
10
+ # load_dotenv()
11
+ # GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
12
+ #
13
+ # if GOOGLE_API_KEY:
14
+ # genai.configure(api_key=GOOGLE_API_KEY)
15
+ # else:
16
+ # st.error("⚠️ Google API Key not found. Please set it in the environment variables.")
17
+ #
18
+ #
19
+ # # Function to get response from Gemini model
20
+ # def get_gemini_response(input_text, image_data):
21
+ # try:
22
+ # model = genai.GenerativeModel('gemini-1.0-pro-vision') # Corrected Model Name
23
+ # response = model.generate_content([input_text, image_data])
24
+ # return response.text
25
+ # except Exception as e:
26
+ # return f"❌ Error: {str(e)}"
27
+ #
28
+ #
29
+ # # Function to process uploaded image
30
+ # def input_image_setup(uploaded_file):
31
+ # if uploaded_file is not None:
32
+ # return Image.open(uploaded_file) # Open image with PIL
33
+ # return None
34
+ #
35
+ #
36
+ # # Streamlit UI Design
37
+ # st.set_page_config(page_title="🧾 Invoice Q&A Chatbot", layout="wide")
38
+ #
39
+ # # Custom Styling (Red Theme)
40
+ # st.markdown("""
41
+ # <style>
42
+ # .title {text-align: center; font-size: 36px; font-weight: bold; color: #D72638;}
43
+ # .subtitle {text-align: center; font-size: 20px; color: #333333;}
44
+ # .footer {text-align: center; font-size: 16px; margin-top: 30px; color: #666666;}
45
+ # .stButton>button {background-color: #D72638; color: white; font-size: 18px; border-radius: 8px; padding: 10px 20px;}
46
+ # .stButton>button:hover {background-color: #A61C2A;}
47
+ # </style>
48
+ # """, unsafe_allow_html=True)
49
+ #
50
+ # # Sidebar for Navigation
51
+ # with st.sidebar:
52
+ # st.image(
53
+ # "img.png",
54
+ # width=250)
55
+ #
56
+ # st.markdown("<h2 style='color: #D72638;'>πŸ” Invoice Q&A Chatbot</h2>", unsafe_allow_html=True)
57
+ # st.markdown("<p>πŸ€– Ask questions about invoices using AI-powered technology.</p>", unsafe_allow_html=True)
58
+ # st.markdown("---")
59
+ # st.markdown("<h3 style='color: #D72638;'>πŸ“Œ Features</h3>", unsafe_allow_html=True)
60
+ # st.markdown("""
61
+ # βœ… AI-Powered Invoice Analysis
62
+ # πŸ“Έ Image-Based Q&A
63
+ # πŸ’¬ Instant Answers
64
+ # ⚑ Fast & Reliable
65
+ # 🎨 Simple & Elegant UI
66
+ # """)
67
+ #
68
+ # # Page Title
69
+ # st.markdown('<p class="title">πŸ“„ Invoice Q&A Chatbot</p>', unsafe_allow_html=True)
70
+ # st.markdown("""
71
+ # <p style="
72
+ # font-size: 18px;
73
+ # font-weight: bold;
74
+ # color: green;
75
+ # text-align: center;
76
+ # margin-top: 10px;">
77
+ # πŸ“Έ Upload an invoice image and ask a question about it.
78
+ # </p>
79
+ # """, unsafe_allow_html=True)
80
+ #
81
+ # # User Input
82
+ # st.write("πŸ’‘ **Enter your question:**")
83
+ # input_text = st.text_input("", key="input", placeholder="E.g. What is the total amount on this invoice?")
84
+ #
85
+ # # File Uploader for Image
86
+ # st.write("πŸ“Έ **Upload an invoice image:**")
87
+ # uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])
88
+ #
89
+ # # Display Uploaded Image
90
+ # image_data = None
91
+ # if uploaded_file:
92
+ # image_data = input_image_setup(uploaded_file)
93
+ # st.image(image_data, caption="πŸ–ΌοΈ Uploaded Invoice", use_column_width=True)
94
+ #
95
+ # # Analyze Button
96
+ # st.markdown("<br>", unsafe_allow_html=True) # Line break for spacing
97
+ # submit = st.button("πŸ” Analyze Image")
98
+ #
99
+ # # Processing
100
+ # if submit:
101
+ # if not uploaded_file:
102
+ # st.error("⚠️ Please upload an invoice image first!")
103
+ # elif not input_text.strip():
104
+ # st.error("⚠️ Please enter a question!")
105
+ # else:
106
+ # st.success("βœ… Processing your request... Please wait.")
107
+ #
108
+ # input_prompt = """
109
+ # You are an AI assistant specializing in invoice analysis.
110
+ # You will receive an invoice image and a question.
111
+ # Provide an accurate answer based on the invoice details.
112
+ # """
113
+ # response = get_gemini_response(input_prompt, image_data)
114
+ #
115
+ # st.subheader("πŸ’‘ AI Response:")
116
+ # st.write(response)
117
+ #
118
+ # # Footer - "Made By"
119
+ # st.markdown('<p class="footer">πŸš€ Made with ❀️ by <b>Prarthana</b></p>', unsafe_allow_html=True)
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ # Import libraries
128
+ from dotenv import load_dotenv
129
+ import streamlit as st
130
+ import os
131
+ from PIL import Image
132
+ import google.generativeai as genai
133
+
134
+ # Load environment variables
135
+ load_dotenv()
136
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
137
+
138
+ if GOOGLE_API_KEY:
139
+ genai.configure(api_key=GOOGLE_API_KEY)
140
+ else:
141
+ st.error("⚠️ Google API Key not found. Please set it in the environment variables.")
142
+
143
+
144
+ # Function to get response from Gemini model
145
+ def get_gemini_response(input_text, image_data):
146
+ try:
147
+ model = genai.GenerativeModel('gemini-1.0-pro-vision') # Corrected Model Name
148
+ response = model.generate_content([input_text, image_data])
149
+ return response.text
150
+ except Exception as e:
151
+ return f"❌ Error: {str(e)}"
152
+
153
+
154
+ # Function to process uploaded image
155
+ def input_image_setup(uploaded_file):
156
+ if uploaded_file is not None:
157
+ return Image.open(uploaded_file) # Open image with PIL
158
+ return None
159
+
160
+
161
+ # Streamlit UI Design
162
+ st.set_page_config(page_title="🧾 Invoice Q&A Chatbot", layout="wide")
163
+
164
+ # Custom Styling (Red Theme)
165
+ st.markdown("""
166
+ <style>
167
+ .title {text-align: center; font-size: 38px; font-weight: bold; color: #D72638; margin-bottom: 10px;}
168
+ .subtitle {text-align: center; font-size: 20px; color: black; margin-bottom: 20px;}
169
+ .upload-text {font-size: 20px; font-weight: bold; color: green; text-align: center; margin-top: 15px;}
170
+ .footer {text-align: center; font-size: 16px; margin-top: 30px; color: #666666;}
171
+ .stButton>button {background-color: #D72638; color: white; font-size: 18px; border-radius: 8px; padding: 12px 25px;}
172
+ .stButton>button:hover {background-color: #A61C2A;}
173
+ </style>
174
+ """, unsafe_allow_html=True)
175
+
176
+ # Sidebar for Navigation
177
+ with st.sidebar:
178
+ st.image("img.png", width=250) # Replaced with a robot image
179
+
180
+ st.markdown("<h2 style='color: #D72638;'>πŸ” Invoice Q&A Chatbot</h2>", unsafe_allow_html=True)
181
+ st.markdown("<p>πŸ€– Ask questions about invoices using AI-powered technology.</p>", unsafe_allow_html=True)
182
+ st.markdown("---")
183
+ st.markdown("<h3 style='color: #D72638;'>πŸ“Œ Features</h3>", unsafe_allow_html=True)
184
+ st.markdown("""
185
+ βœ… AI-Powered Invoice Analysis
186
+ πŸ“Έ Image-Based Q&A
187
+ πŸ’¬ Instant Answers
188
+ ⚑ Fast & Reliable
189
+ 🎨 Simple & Elegant UI
190
+ """)
191
+
192
+ # Page Title
193
+ st.markdown('<p class="title">πŸ“„ Invoice Q&A Chatbot</p>', unsafe_allow_html=True)
194
+ st.markdown('<p class="subtitle">πŸ€– Upload an invoice and ask a question about it.</p>', unsafe_allow_html=True)
195
+
196
+ # User Input
197
+ st.write("πŸ’‘ **Enter your question:**")
198
+ input_text = st.text_input("", key="input", placeholder="E.g. What is the total amount on this invoice?")
199
+
200
+ # File Uploader for Image
201
+ st.markdown('<p class="upload-text">πŸ“Έ Upload an Invoice Image</p>', unsafe_allow_html=True)
202
+ uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])
203
+
204
+ # Display Uploaded Image
205
+ image_data = None
206
+ if uploaded_file:
207
+ image_data = input_image_setup(uploaded_file)
208
+ st.image(image_data, caption="πŸ–ΌοΈ Uploaded Invoice", use_column_width=True)
209
+
210
+ # Analyze Button
211
+ st.markdown("<br>", unsafe_allow_html=True) # Line break for spacing
212
+ submit = st.button("πŸ” Analyze Image")
213
+
214
+ # Processing
215
+ if submit:
216
+ if not uploaded_file:
217
+ st.error("⚠️ Please upload an invoice image first!")
218
+ elif not input_text.strip():
219
+ st.error("⚠️ Please enter a question!")
220
+ else:
221
+ st.success("βœ… Processing your request... Please wait.")
222
+
223
+ input_prompt = """
224
+ You are an AI assistant specializing in invoice analysis.
225
+ You will receive an invoice image and a question.
226
+ Provide an accurate answer based on the invoice details.
227
+ """
228
+ response = get_gemini_response(input_prompt, image_data)
229
+
230
+ st.subheader("πŸ’‘ AI Response:")
231
+ st.write(response)
232
+
233
+ # Footer - "Made By"
234
+ st.markdown('<p class="footer">πŸš€ Made with ❀️ by <b>Prarthana</b></p>', unsafe_allow_html=True)