parthib11 commited on
Commit
be14bd7
·
verified ·
1 Parent(s): 647ccb5

updated file uploader text

Browse files
Files changed (1) hide show
  1. app.py +67 -67
app.py CHANGED
@@ -1,68 +1,68 @@
1
- from dotenv import load_dotenv
2
-
3
- load_dotenv() # take environment variables from .env.
4
-
5
- import streamlit as st
6
- import os
7
- from PIL import Image
8
-
9
-
10
- import google.generativeai as genai
11
-
12
-
13
- os.getenv("GOOGLE_API_KEY")
14
- genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
-
16
- ## Function to load OpenAI model and get respones
17
-
18
- def get_gemini_response(input,image,prompt):
19
- model = genai.GenerativeModel('gemini-1.5-flash')
20
- response = model.generate_content([input,image[0],prompt])
21
- return response.text
22
-
23
-
24
- def input_image_setup(uploaded_file):
25
- # Check if a file has been uploaded
26
- if uploaded_file is not None:
27
- # Read the file into bytes
28
- bytes_data = uploaded_file.getvalue()
29
-
30
- image_parts = [
31
- {
32
- "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
33
- "data": bytes_data
34
- }
35
- ]
36
- return image_parts
37
- else:
38
- raise FileNotFoundError("No file uploaded")
39
-
40
-
41
- ##initialize our streamlit app
42
-
43
- st.set_page_config(page_title="Gemini Image Demo")
44
-
45
- st.header("Multilingual Invoice Extractor")
46
- input=st.text_input("Input Prompt: ",key="input")
47
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
48
- image=""
49
- if uploaded_file is not None:
50
- image = Image.open(uploaded_file)
51
- st.image(image, caption="Uploaded Image.", use_column_width=True)
52
-
53
-
54
- submit=st.button("Tell me about the image")
55
-
56
- input_prompt="""
57
- You are an expert in understanding invoices. We will upload a a image as invoice
58
- and you will have to answer any questions based on the uploaded invoice image. If the required information is not available in the uploaded image,
59
- say it and then try to answer according to your own capability. Also mention that the answer is according to your information.
60
- If the input prompt is not related to the invoice, mention it and then answer according to your capabilities.
61
- """
62
-
63
-
64
- if submit:
65
- image_data = input_image_setup(uploaded_file)
66
- response=get_gemini_response(input_prompt,image_data,input)
67
- st.subheader("The Response is")
68
  st.write(response)
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv() # take environment variables from .env.
4
+
5
+ import streamlit as st
6
+ import os
7
+ from PIL import Image
8
+
9
+
10
+ import google.generativeai as genai
11
+
12
+
13
+ os.getenv("GOOGLE_API_KEY")
14
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
+
16
+ ## Function to load OpenAI model and get respones
17
+
18
+ def get_gemini_response(input,image,prompt):
19
+ model = genai.GenerativeModel('gemini-1.5-flash')
20
+ response = model.generate_content([input,image[0],prompt])
21
+ return response.text
22
+
23
+
24
+ def input_image_setup(uploaded_file):
25
+ # Check if a file has been uploaded
26
+ if uploaded_file is not None:
27
+ # Read the file into bytes
28
+ bytes_data = uploaded_file.getvalue()
29
+
30
+ image_parts = [
31
+ {
32
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
33
+ "data": bytes_data
34
+ }
35
+ ]
36
+ return image_parts
37
+ else:
38
+ raise FileNotFoundError("No file uploaded")
39
+
40
+
41
+ ##initialize our streamlit app
42
+
43
+ st.set_page_config(page_title="Gemini Image Demo")
44
+
45
+ st.header("Multilingual Invoice Extractor")
46
+ input=st.text_input("Input Prompt: ",key="input")
47
+ uploaded_file = st.file_uploader("Choose an image of Invoice...", type=["jpg", "jpeg", "png"])
48
+ image=""
49
+ if uploaded_file is not None:
50
+ image = Image.open(uploaded_file)
51
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
52
+
53
+
54
+ submit=st.button("Tell me about the image")
55
+
56
+ input_prompt="""
57
+ You are an expert in understanding invoices. We will upload a a image as invoice
58
+ and you will have to answer any questions based on the uploaded invoice image. If the required information is not available in the uploaded image,
59
+ say it and then try to answer according to your own capability. Also mention that the answer is according to your information.
60
+ If the input prompt is not related to the invoice, mention it and then answer according to your capabilities.
61
+ """
62
+
63
+
64
+ if submit:
65
+ image_data = input_image_setup(uploaded_file)
66
+ response=get_gemini_response(input_prompt,image_data,input)
67
+ st.subheader("The Response is")
68
  st.write(response)