sanjivinsmoke121 commited on
Commit
7562c50
1 Parent(s): efbe196

Gemini-pro-vision

Browse files
Files changed (2) hide show
  1. app.py +62 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ import streamlit as st
5
+ import os
6
+ from PIL import Image
7
+ import google.generativeai as genai
8
+
9
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
10
+
11
+ # Load Gemini pro Vision
12
+ model = genai.GenerativeModel('gemini-pro-vision')
13
+
14
+ def get_gemini_response(input,image,prompt):
15
+ response = model.generate_content([input,image[0],prompt])
16
+ return response.text
17
+
18
+ def input_image(uploaded_file):
19
+ if uploaded_file is not None:
20
+ bytes_data = uploaded_file.getvalue()
21
+
22
+ image_parts = [
23
+ {
24
+ "mime_type":uploaded_file.type,
25
+ "data":bytes_data
26
+ }
27
+ ]
28
+ return image_parts
29
+ else:
30
+ raise FileNotFoundError("No file uploaded")
31
+
32
+
33
+
34
+ # Streamlit
35
+ st.set_page_config(page_title="Extractor",page_icon=":100:")
36
+ st.header("Quick Info")
37
+ st.subheader("Extract information from images")
38
+ input = st.text_input("Input prompt :",key="input")
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
+
45
+ submit = st.button("Tell me about the image")
46
+
47
+ input_prompt = """
48
+ You are an expert in understanding images. We will upload an image
49
+ and you will have to answer any question based on the uploaded image
50
+ """
51
+
52
+ if submit:
53
+ image_data = input_image(uploaded_file)
54
+ response = get_gemini_response(input,image_data,input_prompt)
55
+ st.subheader("The response :")
56
+ st.write(response)
57
+
58
+
59
+
60
+
61
+
62
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ langchain
5
+ PyPDF2
6
+ chromadb