-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
45 lines (32 loc) · 1.24 KB
/
app.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
import streamlit as st
from PIL import Image
from dotenv import load_dotenv
import os
import google.generativeai as genai
load_dotenv()
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
model = genai.GenerativeModel("gemini-pro-vision")
# function for Gemini Pro Vision API call
def gemini_pro_vision_api(image, prompt):
# Simulate a response from the API
if prompt != "":
response = model.generate_content([prompt,image])
else:
response = model.generate_content(image)
return response.text
def main():
st.title("Gemini Pro Vision Image Recognition")
# File uploader for image upload
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
# Prompt text box
prompt = st.text_input("Enter your prompt:", "Describe the image content")
if uploaded_file is not None:
# Display the uploaded image
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
# Call the Gemini Pro Vision API
response = gemini_pro_vision_api(image, prompt)
# Display the API response
st.write("Generated information from Gemini", response)
if __name__ == "__main__":
main()