|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
import streamlit as st
|
|
import os
|
|
|
|
import PIL.Image
|
|
|
|
import google.generativeai as genai
|
|
|
|
genai.configure(api_key=os.getenv("gkey2"))
|
|
|
|
model = genai.GenerativeModel('gemini-pro-vision')
|
|
|
|
def get_gemini_response(prompt,img,input):
|
|
|
|
response=model.generate_content([prompt,img,input])
|
|
return response.text
|
|
|
|
st.set_page_config(page_title='Gemini Multlanguage Invoice Extractor')
|
|
st.header('Gemini LLm Application')
|
|
input=st.text_input("Input :",key='input')
|
|
imgupload=st.file_uploader('Choose Invoice File',type=['jpg','jpeg','png'])
|
|
|
|
img=""
|
|
if imgupload is not None:
|
|
img=PIL.Image.open(imgupload)
|
|
st.image(img,caption='Uploaded Image',use_column_width=True)
|
|
else:
|
|
|
|
st.write("Please upload an image file.")
|
|
|
|
submit=st.button('Query Invoice')
|
|
|
|
input_prompt="""
|
|
You are an expert in understanding invoices.We will upload a
|
|
image as invoice and you will answer any questions based on the uploaded invoice.
|
|
"""
|
|
if submit:
|
|
response=get_gemini_response(input_prompt,img,input)
|
|
st.subheader('Response is :')
|
|
st.write(response)
|
|
|