srinidhidevaraj commited on
Commit
1932c5d
1 Parent(s): aeab473

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv()
4
+ import streamlit as st
5
+ import os
6
+ # from PIL import Image
7
+ import PIL.Image
8
+
9
+ import google.generativeai as genai
10
+
11
+ genai.configure(api_key=os.getenv("gkey2"))
12
+
13
+ model = genai.GenerativeModel('gemini-pro-vision')
14
+
15
+ def get_gemini_response(prompt,img,input):
16
+ # input,img,prompt
17
+ response=model.generate_content([prompt,img,input])
18
+ return response.text
19
+
20
+ st.set_page_config(page_title='Gemini Multlanguage Invoice Extractor')
21
+ st.header('Gemini LLm Application')
22
+ input=st.text_input("Input :",key='input')
23
+ imgupload=st.file_uploader('Choose Invoice File',type=['jpg','jpeg','png'])
24
+
25
+ img=""
26
+ if imgupload is not None:
27
+ img=PIL.Image.open(imgupload)
28
+ st.image(img,caption='Uploaded Image',use_column_width=True)
29
+ else:
30
+
31
+ st.write("Please upload an image file.")
32
+
33
+ submit=st.button('Query Invoice')
34
+
35
+ input_prompt="""
36
+ You are an expert in understanding invoices.We will upload a
37
+ image as invoice and you will answer any questions based on the uploaded invoice.
38
+ """
39
+ if submit:
40
+ response=get_gemini_response(input_prompt,img,input)
41
+ st.subheader('Response is :')
42
+ st.write(response)