File size: 2,065 Bytes
e8d8419
7c64620
 
 
e8d8419
 
7c64620
e8d8419
243a9d1
7c64620
e8d8419
 
7c64620
e8d8419
 
 
 
 
 
 
 
7c64620
e8d8419
7c64620
e8d8419
 
7c64620
 
 
 
e8d8419
 
243a9d1
7c64620
e8d8419
7c64620
 
 
76f96e7
 
 
 
e8d8419
 
 
 
4f24828
7c64620
e8d8419
7c64620
 
 
 
e8d8419
 
7c64620
e8d8419
 
7c64620
e8d8419
 
d573a53
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
53
54
55
56
57
58
59
60
61
62
63
# Load all environment variables
from dotenv import load_dotenv
load_dotenv()

# Import required packages and libraries
import streamlit as st  # Streamlit to create a web application
import os
import google.generativeai as genai  # The primary LLM model that resides inside genAI library
from PIL import Image

# Fetch the API key that is defined inside .env
google_api_key = os.getenv("GOOGLE_API_KEY")

if google_api_key is None:
    st.error("API key not found. Please check your .env file.")
    st.stop()

# Configure genAI library with the fetched API key
genai.configure(api_key=google_api_key)

# Function that loads Gemini Model and returns the response
def get_model_response(query, user_image):
    # Create a GenerativeModel instance with the 'gemini-pro-vision' model
    model = genai.GenerativeModel('gemini-pro-vision')

    # Check if a query is provided and generate content accordingly
    if query != "":
        model_response = model.generate_content([query, user_image])
    else:
        model_response = model.generate_content(user_image)

    # Extract and return the text from the model response
    return model_response.text

# Set page configuration
st.set_page_config(page_title="Visualize Image-Text")
st.header("Poulta App Image Analyses")

# Add logo
logo_image_url = "https://poulta.com/assets/site-images/poulta-logo.png"
st.image(logo_image_url, width=200)  # Adjust width as needed

# User input for query
user_input = st.text_input("What do you want to know about the image? ", key="user_input")

# File uploader for image
uploaded_file = st.file_uploader("Pick your image...", type=["jpg", "jpeg", "png"])

image = ""
if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image.", use_column_width=True)

# Button to trigger image analysis
submit = st.button("See the magic ✨")
if submit:
    # Perform model analysis and display results
    model_response = get_model_response(user_input, image)
    st.subheader("Results here 👇🏻")
    st.write(model_response)