Upload 2 files
Browse files- app.py +39 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#load all environment variables
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
load_dotenv()
|
| 4 |
+
|
| 5 |
+
#Import required packages and libraries
|
| 6 |
+
import streamlit as st #Streamlit to create web application
|
| 7 |
+
import os
|
| 8 |
+
import google.generativeai as genai #The primary LLM model that resides inside genAI library
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
#Fetch the API key that is defined inside .env
|
| 12 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 13 |
+
|
| 14 |
+
#Function that loads Gemini Model and returns the response
|
| 15 |
+
def get_model_response(query, user_image):
|
| 16 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
| 17 |
+
if query != "":
|
| 18 |
+
model_response = model.generate_content([query, user_image])
|
| 19 |
+
else:
|
| 20 |
+
model_response = model.generate_content(user_image)
|
| 21 |
+
return model_response.text
|
| 22 |
+
|
| 23 |
+
#Set up Streamlit application to visualize results
|
| 24 |
+
st.set_page_config(page_title="Visualize Image-Text")
|
| 25 |
+
st.header("Poulta App Image Analyses")
|
| 26 |
+
|
| 27 |
+
user_input=st.text_input("What do you want to know about the image ? ",key="user_input")
|
| 28 |
+
uploaded_file = st.file_uploader("Pick your image ...", type=["jpg", "jpeg", "png"])
|
| 29 |
+
|
| 30 |
+
image=""
|
| 31 |
+
if uploaded_file is not None:
|
| 32 |
+
image = Image.open(uploaded_file)
|
| 33 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 34 |
+
|
| 35 |
+
submit=st.button("See the magic ✨")
|
| 36 |
+
if submit:
|
| 37 |
+
model_response=get_model_response(user_input, image)
|
| 38 |
+
st.subheader("Results here 👇🏻")
|
| 39 |
+
st.write(model_response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
google-generativeai
|
| 3 |
+
python-dotenv
|