Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- .env +1 -0
- app.py +69 -0
- requirements.txt +3 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
GOOGLE_API_KEY="AIzaSyDs9p7qZMOl8XG_th5QPZ7ILgMlhzSxSBw"
|
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### Invoice extractor
|
2 |
+
|
3 |
+
##Importing All the modules
|
4 |
+
import streamlit as st
|
5 |
+
import os
|
6 |
+
from PIL import Image
|
7 |
+
import google.generativeai as genai
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
|
10 |
+
|
11 |
+
# Load all environment Variables
|
12 |
+
load_dotenv()
|
13 |
+
|
14 |
+
##Configuring the api key
|
15 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
16 |
+
|
17 |
+
## Function to load Gemini Vison Pro Vision Model and Get response
|
18 |
+
|
19 |
+
def get_gemini_response(input,image,prompt):
|
20 |
+
|
21 |
+
##Loading the desired Model
|
22 |
+
model= genai.GenerativeModel("gemini-pro-vision")
|
23 |
+
response=model.generate_content([input,image[0],prompt])
|
24 |
+
return response.text
|
25 |
+
|
26 |
+
## Function to extract data from Image Uploaded
|
27 |
+
def input_image_setup(uploaded_file):
|
28 |
+
# Check if a file has been uploaded
|
29 |
+
if uploaded_file is not None:
|
30 |
+
# Read the file into bytes
|
31 |
+
bytes_data = uploaded_file.getvalue()
|
32 |
+
|
33 |
+
image_parts = [
|
34 |
+
{
|
35 |
+
"mime_type": uploaded_file.type, # Get the mime type of the uploaded file
|
36 |
+
"data": bytes_data
|
37 |
+
}
|
38 |
+
]
|
39 |
+
return image_parts
|
40 |
+
else:
|
41 |
+
raise FileNotFoundError("No file uploaded")
|
42 |
+
|
43 |
+
# Initializing our Streamlit Prompt
|
44 |
+
|
45 |
+
st.set_page_config(page_title="Gemini Image Demo")
|
46 |
+
|
47 |
+
st.header("Gemini Application")
|
48 |
+
input=st.text_input("Input Prompt: ",key="input")
|
49 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
50 |
+
image=""
|
51 |
+
if uploaded_file is not None:
|
52 |
+
image = Image.open(uploaded_file)
|
53 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
54 |
+
|
55 |
+
|
56 |
+
submit=st.button("Tell me about the image")
|
57 |
+
|
58 |
+
## DEFINING A SYSTEM PROMPT
|
59 |
+
|
60 |
+
input_prompt = "You are an expert in understanding invoices.You will receive invoices as input images and you will have to answer question based on the input image."
|
61 |
+
|
62 |
+
if submit:
|
63 |
+
image_data = input_image_setup(uploaded_file)
|
64 |
+
response = get_gemini_response(input_prompt,image_data,input)
|
65 |
+
|
66 |
+
st.subheader("The Response Generated by your model Gemini Pro Vision is: ")
|
67 |
+
st.write(response)
|
68 |
+
|
69 |
+
st.balloons()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
google-generativeai
|
2 |
+
streamlit
|
3 |
+
python-dotenv
|