garyd1 commited on
Commit
0fb75ab
·
verified ·
1 Parent(s): 6374c9f

Create vision.py

Browse files
Files changed (1) hide show
  1. vision.py +52 -0
vision.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+ #from langchain.llms import OpenAI
3
+
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv() # take environment variables from .env.
7
+
8
+ import streamlit as st
9
+ import os
10
+ import pathlib
11
+ import textwrap
12
+ from PIL import Image
13
+
14
+
15
+ import google.generativeai as genai
16
+
17
+
18
+ os.getenv("GOOGLE_API_KEY")
19
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
20
+
21
+ ## Function to load OpenAI model and get respones
22
+
23
+ def get_gemini_response(input,image):
24
+ model = genai.GenerativeModel('gemini-pro-vision')
25
+ if input!="":
26
+ response = model.generate_content([input,image])
27
+ else:
28
+ response = model.generate_content(image)
29
+ return response.text
30
+
31
+ ##initialize our streamlit app
32
+
33
+ st.set_page_config(page_title="Gemini Image Demo")
34
+
35
+ st.header("Gemini Application")
36
+ input=st.text_input("Input Prompt: ",key="input")
37
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
38
+ image=""
39
+ if uploaded_file is not None:
40
+ image = Image.open(uploaded_file)
41
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
42
+
43
+
44
+ submit=st.button("Tell me about the image")
45
+
46
+ ## If ask button is clicked
47
+
48
+ if submit:
49
+
50
+ response=get_gemini_response(input,image)
51
+ st.subheader("The Response is")
52
+ st.write(response)