Spaces:
Sleeping
Sleeping
File size: 1,588 Bytes
fcefef0 afdb550 fcefef0 1ec43fc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import os
import google.generativeai as genai
from PIL import Image
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# load gemini model
model=genai.GenerativeModel("gemini-1.5-flash")
def get_gemini_response(input,image,prompt):
response=model.generate_content([input,image[0],prompt])
return response.text
def input_image_setup(uploaded_img):
if uploaded_img is not None:
bytes_data = uploaded_img.getvalue()
image_parts=[
{
"mime_type": uploaded_img.type,
"data": bytes_data
}
]
return image_parts
else:
raise FileNotFoundError("Image not found")
st.set_page_config(page_title="Invoice extractor", page_icon="🔮")
st.title("Invoice Extractor using LLM")
st.write("Upload your invoice and we will give you all the information we can based on your query")
input = st.text_input("Ask a question", key="input")
uploaded_img = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
image=""
if uploaded_img is not None:
image = Image.open(uploaded_img)
st.image(image, caption="Uploaded Image.", use_column_width=True)
submit=st.button("Submit")
input_prompt="""
You are expert in understanding invoices. We will show you an invoice and you have to answer the following questions based on the invoice:
"""
if submit:
image_data=input_image_setup(uploaded_img)
response=get_gemini_response(input_prompt,image_data,input)
st.subheader("Response:")
st.write(response) |