Upload 2 files
Browse files- Extractor.py +56 -0
- requirements.txt +6 -0
Extractor.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv() # Load the all envirement variable from .env
|
| 3 |
+
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
import google.generativeai as genai
|
| 10 |
+
genai.configure(api_key=os.getenv("google_api_key"))
|
| 11 |
+
model=genai.GenerativeModel('gemini-1.5-flash') # Load gemini pero version Model
|
| 12 |
+
|
| 13 |
+
def get_gemini_response(input,image,user_prompt):
|
| 14 |
+
response=model.generate_content([input,image[0],user_prompt])
|
| 15 |
+
return response.text
|
| 16 |
+
|
| 17 |
+
def input_image_details(uploaded_file):
|
| 18 |
+
if uploaded_file is not None:
|
| 19 |
+
bytes_data=uploaded_file.getvalue() # Read the files into bytes
|
| 20 |
+
image_parts=[
|
| 21 |
+
{
|
| 22 |
+
"mine type":uploaded_file.type, # get th mime type of the uploaded file
|
| 23 |
+
"data":bytes_data
|
| 24 |
+
}
|
| 25 |
+
]
|
| 26 |
+
return image_parts
|
| 27 |
+
else:
|
| 28 |
+
raise FileNotFoundError("No file uploaded")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# Initialize our streamlit app
|
| 32 |
+
|
| 33 |
+
st.set_page_config(page_title='Multilanguage Invoice Extractor')
|
| 34 |
+
|
| 35 |
+
st.header('Multilanguage Invoice Extractor')
|
| 36 |
+
input=st.text_input("input prompt:",key="input")
|
| 37 |
+
|
| 38 |
+
uploaded_file=st.file_uploader("Chose an image of the Invoice....",type=["jpg","jpeg","png"])
|
| 39 |
+
|
| 40 |
+
if uploaded_file is not None:
|
| 41 |
+
image=Image.open(uploaded_file)
|
| 42 |
+
st.image(image,caption="uploaded image.",use_column_width=True)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
input_prompt="""
|
| 46 |
+
You are an expert in understanding invoices. We upload a image as invoice
|
| 47 |
+
and you will have to answer any quetions based on the uploaded invoice image
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
submit=st.button('Tell me about the invoice')
|
| 51 |
+
|
| 52 |
+
if submit:
|
| 53 |
+
image_data=input_image_details(uploaded_file)
|
| 54 |
+
response=get_gemini_response(input_prompt,image_data,input)
|
| 55 |
+
st.subheader("The Response is")
|
| 56 |
+
st.write(response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
google-generativeai # To create LLM model of google
|
| 3 |
+
python-dotenv # For hide my API key
|
| 4 |
+
langchain
|
| 5 |
+
pyPDF2 # To process pdf file
|
| 6 |
+
chromadb # vector database
|