Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,9 @@ import google.generativeai as genai
|
|
8 |
|
9 |
genai.configure(api_key='AIzaSyCeNgXfZx0kJ736XFVtxXxev_RdscB0i5s')
|
10 |
|
11 |
-
|
|
|
|
|
12 |
model = genai.GenerativeModel('gemini-pro-vision')
|
13 |
response = model.generate_content([input,image[0],prompt])
|
14 |
return response.text
|
@@ -17,12 +19,12 @@ def get_gemini_response(input, image,prompt):
|
|
17 |
def input_image_setup(uploaded_file):
|
18 |
# Check if a file has been uploaded
|
19 |
if uploaded_file is not None:
|
20 |
-
|
21 |
bytes_data = uploaded_file.getvalue()
|
22 |
|
23 |
image_parts = [
|
24 |
{
|
25 |
-
"mime_type": uploaded_file.type,
|
26 |
"data": bytes_data
|
27 |
}
|
28 |
]
|
@@ -31,33 +33,32 @@ def input_image_setup(uploaded_file):
|
|
31 |
raise FileNotFoundError("No file uploaded")
|
32 |
|
33 |
|
34 |
-
##streamlit app
|
35 |
|
36 |
st.set_page_config(page_title="Gemini Image Demo")
|
37 |
|
38 |
-
st.header("Generative AI : Business
|
|
|
39 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
40 |
image=""
|
41 |
if uploaded_file is not None:
|
42 |
image = Image.open(uploaded_file)
|
43 |
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
44 |
-
input=st.text_input("Input Prompt (optional) : ",key="input")
|
45 |
|
46 |
|
47 |
submit=st.button("Submit")
|
48 |
|
49 |
input_prompt = """
|
50 |
You are an expert in understanding business cards.
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
Constraints: Do not include missing information.
|
55 |
"""
|
56 |
|
|
|
|
|
57 |
if submit:
|
58 |
image_data = input_image_setup(uploaded_file)
|
59 |
-
response=get_gemini_response(input_prompt,image_data,
|
60 |
st.subheader("Output :")
|
61 |
-
st.write(response)
|
62 |
-
|
63 |
-
examples = ['examples/Business_card.jpg', 'examples/Business_card10.jpg']
|
|
|
8 |
|
9 |
genai.configure(api_key='AIzaSyCeNgXfZx0kJ736XFVtxXxev_RdscB0i5s')
|
10 |
|
11 |
+
## Function to load OpenAI model and get respones
|
12 |
+
|
13 |
+
def get_gemini_response(input,image,prompt):
|
14 |
model = genai.GenerativeModel('gemini-pro-vision')
|
15 |
response = model.generate_content([input,image[0],prompt])
|
16 |
return response.text
|
|
|
19 |
def input_image_setup(uploaded_file):
|
20 |
# Check if a file has been uploaded
|
21 |
if uploaded_file is not None:
|
22 |
+
# Read the file into bytes
|
23 |
bytes_data = uploaded_file.getvalue()
|
24 |
|
25 |
image_parts = [
|
26 |
{
|
27 |
+
"mime_type": uploaded_file.type, # Get the mime type of the uploaded file
|
28 |
"data": bytes_data
|
29 |
}
|
30 |
]
|
|
|
33 |
raise FileNotFoundError("No file uploaded")
|
34 |
|
35 |
|
36 |
+
##initialize our streamlit app
|
37 |
|
38 |
st.set_page_config(page_title="Gemini Image Demo")
|
39 |
|
40 |
+
st.header("Generative AI : Business card Reader")
|
41 |
+
input=st.text_input("Input Prompt: ",key="input")
|
42 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
43 |
image=""
|
44 |
if uploaded_file is not None:
|
45 |
image = Image.open(uploaded_file)
|
46 |
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
|
|
47 |
|
48 |
|
49 |
submit=st.button("Submit")
|
50 |
|
51 |
input_prompt = """
|
52 |
You are an expert in understanding business cards.
|
53 |
+
You will receive input images of business card & you will have to answer questions based on the input image.
|
54 |
+
You have to extract information from business card images and give correct tag to the output text
|
55 |
+
like person name, company name, occupation, address, telephone number, mobile number, email, website, etc. Give output in json format.
|
|
|
56 |
"""
|
57 |
|
58 |
+
## If ask button is clicked
|
59 |
+
|
60 |
if submit:
|
61 |
image_data = input_image_setup(uploaded_file)
|
62 |
+
response=get_gemini_response(input_prompt,image_data,input)
|
63 |
st.subheader("Output :")
|
64 |
+
st.write(response)
|
|
|
|