Spaces:
Runtime error
Runtime error
A-Jyothi-11
commited on
Commit
•
1a87813
1
Parent(s):
1d62f0a
Upload 2 files
Browse files- app.py +48 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#AIzaSyBSA2bVH9C5uO4mwVE3OS12YMKa5D9AR1Q
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
load_dotenv() #load all environment variables from .env
|
4 |
+
import streamlit as st
|
5 |
+
from PIL import Image
|
6 |
+
import google.generativeai as genai
|
7 |
+
import os
|
8 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
9 |
+
|
10 |
+
model = genai.GenerativeModel('gemini-pro')
|
11 |
+
|
12 |
+
def get_gemini_response(input,image,prompt):
|
13 |
+
response=model.generate_content([input,image[0],prompt])
|
14 |
+
return response.text
|
15 |
+
|
16 |
+
def input_image_seetup(uploaded_file):
|
17 |
+
if uploaded_file is not None:
|
18 |
+
byte_data = uploaded_file.getvalue()
|
19 |
+
imaage_parts = [
|
20 |
+
{
|
21 |
+
"mime_type":uploaded_file.type,
|
22 |
+
"data" : byte_data
|
23 |
+
}
|
24 |
+
]
|
25 |
+
return imaage_parts
|
26 |
+
else:
|
27 |
+
raise FileNotFoundError("No file uploaded")
|
28 |
+
|
29 |
+
st.set_page_config(page_title="MultiLanguage Invoice Extractor")
|
30 |
+
|
31 |
+
st.header('Gemini Application')
|
32 |
+
input=st.text_input("Input Prompt: ",key="Input")
|
33 |
+
uploaded_file = st.file_uploader('Choose an image.. ',type=["jpg","png","jpeg"])
|
34 |
+
image = ""
|
35 |
+
if uploaded_file is not None:
|
36 |
+
image = Image.open(uploaded_file)
|
37 |
+
st.image(image,caption="Uploaded Image",use_column_width=True)
|
38 |
+
|
39 |
+
submit = st.button("Tell me about the invoice")
|
40 |
+
|
41 |
+
input_prompt="""
|
42 |
+
You are an expert in understanding invoices. We will upload a image as invoice and you will have to answer any questions based on the uploaded invoice image"""
|
43 |
+
|
44 |
+
if submit:
|
45 |
+
image_data =input_image_seetup(uploaded_file)
|
46 |
+
response=get_gemini_response(input_prompt,image_data,input)
|
47 |
+
st.subheader("The Response is")
|
48 |
+
st.write(response)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|
4 |
+
langchain
|
5 |
+
PyPDF2
|
6 |
+
chromadb
|