Spaces:
Sleeping
Sleeping
File size: 1,145 Bytes
01d3883 6a73001 01d3883 ca5958b 01d3883 |
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 |
import streamlit as st
from PIL import Image
import google.generativeai as genai
import os
gemini_api_key = genai.configure(api_key = os.environ.get("Google_API_KEY"))
model = genai.GenerativeModel('gemini-1.5-flash')
input_prompts = """
You are an expert Invoice Entity Extractor and you are expert in understanding Invoices.
We will upload an image as Invoice and you will have to answer any question based on the uploaded invoice.
"""
def response_gemini(input, image, prompt):
response = model.generate_content([input, image[0], prompt])
return response.text
st.title("Invoice Entity Extractor")
uploaded_file = st.file_uploader("Choose an invoice image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Invoice', use_column_width=True)
question = st.text_input("Ask a question about the invoice:")
if st.button("Extract"):
if question:
answer = response_gemini(input_prompts, [image], question)
#st.write("**Answer:**", answer)
st.markdown(f"**Answer:** {answer}")
else:
st.warning("Please enter a question.") |