Spaces:
Sleeping
Sleeping
App
Browse files- .env +1 -0
- app.py +53 -0
- requirements.txt +6 -0
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GOOGLE_API_KEY="AIzaSyAVhmqKi7Tzc5RGSIdAI5LsVXu2W9NEU0A"
|
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv()
|
| 3 |
+
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import google.generativeai as genai
|
| 8 |
+
|
| 9 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 10 |
+
|
| 11 |
+
## function to load Gemini pro vision
|
| 12 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
| 13 |
+
|
| 14 |
+
def get_gemini_response(input, image, prompt):
|
| 15 |
+
response = model.generate_content([input, image[0], prompt])
|
| 16 |
+
return response.text
|
| 17 |
+
|
| 18 |
+
def input_image_setup(upload_file):
|
| 19 |
+
if upload_file is not None:
|
| 20 |
+
bytes_data = upload_file.getvalue()
|
| 21 |
+
image_parts = [
|
| 22 |
+
{
|
| 23 |
+
"mime_type": upload_file.type,
|
| 24 |
+
"data": bytes_data
|
| 25 |
+
}
|
| 26 |
+
]
|
| 27 |
+
return image_parts
|
| 28 |
+
else:
|
| 29 |
+
raise FileNotFoundError("No file uploaded")
|
| 30 |
+
|
| 31 |
+
st.set_page_config(page_title="Multilanguage Invoice Extractor")
|
| 32 |
+
|
| 33 |
+
st.header("Gemini Application")
|
| 34 |
+
input = st.text_input("Input Prompt: ", key="input")
|
| 35 |
+
upload_file = st.file_uploader("Choose an image of invoice ", type=["jpg", "jpeg", "png"])
|
| 36 |
+
|
| 37 |
+
image=""
|
| 38 |
+
if upload_file is not None:
|
| 39 |
+
image = Image.open(upload_file)
|
| 40 |
+
st.image(image, caption="uploaded Image", use_column_width=True)
|
| 41 |
+
|
| 42 |
+
submit = st.button("Tell me about invoice")
|
| 43 |
+
|
| 44 |
+
input_prompt ="""
|
| 45 |
+
You are an export in understanding invoices.
|
| 46 |
+
we will upload an image as invoice and you will habe to answer any question based on uploaded invoice image
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
if submit:
|
| 50 |
+
image_data = input_image_setup(upload_file)
|
| 51 |
+
response = get_gemini_response(input_prompt, image_data, input)
|
| 52 |
+
st.subheader("The response is ")
|
| 53 |
+
st.write(response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
google-generativeai
|
| 3 |
+
python-dotenv
|
| 4 |
+
langchain
|
| 5 |
+
PyPDF2
|
| 6 |
+
chromadb
|