-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision.py
52 lines (43 loc) · 1.64 KB
/
vision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
from dotenv import load_dotenv
import streamlit as st
from PIL import Image
import google.generativeai as genai
# Load environment variables from .env
load_dotenv()
# Configure the Google API key
api_key = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=api_key)
# Function to get response from the updated Gemini model
def get_gemini_response(input_text, image):
model = genai.GenerativeModel("gemini-1.5-flash") # Use the correct model ID
if input_text and image:
response = model.generate_content([input_text, image])
elif input_text:
response = model.generate_content([input_text])
elif image:
response = model.generate_content([image])
else:
response = None
return response.text if response else "No response available."
# Initialize Streamlit app
st.set_page_config(page_title="Gemini Image Demo")
st.header("image recognizer Application")
# Input text prompt
input_text = st.text_input("Input Prompt:", key="input")
# Image uploader
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
image = None
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image.", use_column_width=True)
# Submit button
submit = st.button("Tell me about the image")
# Generate and display the response if submit is clicked
if submit:
if input_text or image:
response = get_gemini_response(input_text, image)
st.subheader("The Response is:")
st.write(response)
else:
st.write("Please provide either an input prompt or an image.")