Spaces:
Running
Running
Upload 2 files
Browse files- app.py +38 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 10 |
+
|
| 11 |
+
## Function to load Gemini-pro-vision model and get respones
|
| 12 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
| 13 |
+
def get_gemini_response(input, image):
|
| 14 |
+
if input != " ":
|
| 15 |
+
response = model.generate_content([input, image])
|
| 16 |
+
else:
|
| 17 |
+
response = model.generate_content(image)
|
| 18 |
+
return response.text
|
| 19 |
+
|
| 20 |
+
##initialize our streamlit app
|
| 21 |
+
|
| 22 |
+
st.set_page_config(page_title="Gemini Image Demo")
|
| 23 |
+
|
| 24 |
+
st.header("Gemini Application")
|
| 25 |
+
input=st.text_input("Input Prompt: ",key="input")
|
| 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 |
+
submit=st.button("Tell me about the image")
|
| 33 |
+
|
| 34 |
+
## If ask button is clicked
|
| 35 |
+
if submit:
|
| 36 |
+
response=get_gemini_response(input,image)
|
| 37 |
+
st.subheader("The Response is")
|
| 38 |
+
st.write(response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
google-generativeai
|
| 3 |
+
python-dotenv
|