Upload app2.py
Browse files
app2.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 5 |
+
import google.generativeai as genai
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 10 |
+
|
| 11 |
+
# for m in genai.list_models():
|
| 12 |
+
# print(m.name)
|
| 13 |
+
|
| 14 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 15 |
+
model = genai.GenerativeModel("gemini-pro-vision")
|
| 16 |
+
|
| 17 |
+
def get_response(input , image):
|
| 18 |
+
if input != "" :
|
| 19 |
+
response = model.generate_content([input,image])
|
| 20 |
+
else:
|
| 21 |
+
response = model.generate_content(image)
|
| 22 |
+
return response.text
|
| 23 |
+
|
| 24 |
+
st.set_page_config(page_title = "Demo")
|
| 25 |
+
|
| 26 |
+
st.header("Testing")
|
| 27 |
+
input = st.text_input("Enter the input" , key = "input")
|
| 28 |
+
uploaded_file = st.file_uploader("Choose an Image" , type = ["jpg", "png" , "jpeg"])
|
| 29 |
+
image = ""
|
| 30 |
+
|
| 31 |
+
if uploaded_file is not None:
|
| 32 |
+
image = Image.open(uploaded_file)
|
| 33 |
+
st.image(image)
|
| 34 |
+
|
| 35 |
+
submit = st.button("Click Here")
|
| 36 |
+
|
| 37 |
+
if submit:
|
| 38 |
+
response = get_response(input , image)
|
| 39 |
+
st.write(response)
|