Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import google.generativeai as genai
|
4 |
+
from google.colab import userdata
|
5 |
+
|
6 |
+
gemini_api_key = genai.configure(api_key = os.environ.get("Google_API_KEY"))
|
7 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
8 |
+
|
9 |
+
input_prompts = """
|
10 |
+
You are an expert Invoice Entity Extractor and you are expert in understanding Invoices.
|
11 |
+
We will upload an image as Invoice and you will have to answer any question based on the uploaded invoice.
|
12 |
+
"""
|
13 |
+
|
14 |
+
def response_gemini(input, image, prompt):
|
15 |
+
response = model.generate_content([input, image[0], prompt])
|
16 |
+
return response.text
|
17 |
+
|
18 |
+
st.title("Invoice Entity Extractor")
|
19 |
+
|
20 |
+
uploaded_file = st.file_uploader("Choose an invoice image", type=["jpg", "jpeg", "png"])
|
21 |
+
|
22 |
+
if uploaded_file is not None:
|
23 |
+
image = Image.open(uploaded_file)
|
24 |
+
st.image(image, caption='Uploaded Invoice', use_column_width=True)
|
25 |
+
|
26 |
+
question = st.text_input("Ask a question about the invoice:")
|
27 |
+
if st.button("Extract"):
|
28 |
+
if question:
|
29 |
+
answer = response_gemini(input_prompts, [image], question)
|
30 |
+
#st.write("**Answer:**", answer)
|
31 |
+
st.markdown(f"**Answer:** {answer}")
|
32 |
+
else:
|
33 |
+
st.warning("Please enter a question.")
|