Init
Browse files- requirements.txt +3 -0
- vision.py +39 -0
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
google-generativeai
|
| 3 |
+
python-dotenv
|
vision.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import google.generativeai as genai
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 7 |
+
|
| 8 |
+
## function to load Gemini Pro model and get responses
|
| 9 |
+
model=genai.GenerativeModel("gemini-pro-vision")
|
| 10 |
+
|
| 11 |
+
def get_gemini_response(input, image):
|
| 12 |
+
if input != "":
|
| 13 |
+
response=model.generate_content([input, image])
|
| 14 |
+
else:
|
| 15 |
+
response=model.generate_content(image)
|
| 16 |
+
return response.text
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## initalize our streamlit app
|
| 20 |
+
|
| 21 |
+
st.set_page_config(page_title="Gemini Image Demo")
|
| 22 |
+
|
| 23 |
+
st.header("Gemini Application")
|
| 24 |
+
input = st.text_input("Input Prompt: ", key = "input")
|
| 25 |
+
|
| 26 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 27 |
+
image = ""
|
| 28 |
+
if uploaded_file is not None:
|
| 29 |
+
image = Image.open(uploaded_file)
|
| 30 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
submit=st.button("Tell me about the image")
|
| 34 |
+
|
| 35 |
+
## if submit is clicked
|
| 36 |
+
if submit:
|
| 37 |
+
response = get_gemini_response(input, image)
|
| 38 |
+
st.subheader("The Response is")
|
| 39 |
+
st.write(response)
|