tushargandhi77/MultiLanguage_invoice_Extractor
0
1from dotenv import load_dotenv2 3load_dotenv() ## load all the evironment variables from .env4 5 6import streamlit as st7import os8from PIL import Image9import google.generativeai as genai10 11genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))12 13## fuction to load gemini pro vision14 15model = genai.GenerativeModel('gemini-1.5-flash')16 17def get_gemini_response(input,image,prompt):18 response = model.generate_content([input,image[0],prompt])19 return response.text20 21def input_image_setup(upload_file):22 if upload_file is not None:23 bytes_data = upload_file.getvalue()24 25 image_parts = [26 {27 "mime_type":upload_file.type,28 "data": bytes_data29 }30 ]31 return image_parts32 else:33 raise ValueError("No file uploaded")34 35 36st.set_page_config(page_title="MultiLanguage invoice Extractor")37 38st.header("MultiLanguage Invoice Extractor")39 40input=st.text_input("Input Prompt: ",key="input")41upload_file = st.file_uploader("Choose an image ",type=['jpg','jpeg','png'])42 43image = ""44if upload_file is not None:45 image = Image.open(upload_file)46 st.image(image,caption="uploaded Image",use_column_width=True)47 48submit = st.button("Tell me about the invoice")49 50input_prompts = """51You are an expert in understanding invoices. We will upload a image as invoice and you will have to answer any question based on uploaded invoice image52"""53 54# if sumbit is clicked55 56if submit:57 image_data = input_image_setup(upload_file)58 response = get_gemini_response(input_prompts,image_data,input)59 st.subheader("The Response is")60 st.subheader(response)