Spaces:
Runtime error
Runtime error
Commit
·
9d2fdc3
1
Parent(s):
6278b5f
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
|
| 3 |
-
load_dotenv()
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
import os
|
|
@@ -8,38 +11,42 @@ import pathlib
|
|
| 8 |
import textwrap
|
| 9 |
from PIL import Image
|
| 10 |
|
|
|
|
| 11 |
import google.generativeai as genai
|
| 12 |
|
| 13 |
-
os.getenv("GOOGLE_API_KEYS")
|
| 14 |
-
genai.configure(api_keys = os.getenv("GOOGLE_API_KEYS"))
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
def get_gemini_response(input,image)
|
| 19 |
model = genai.GenerativeModel('gemini-pro-vision')
|
| 20 |
if input!="":
|
| 21 |
-
|
| 22 |
else:
|
| 23 |
-
|
| 24 |
-
return response.text
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
st.header("Decoding Data Science
|
| 30 |
-
input
|
| 31 |
-
uploaded_file = st.file_uploader("Choose an
|
| 32 |
-
|
| 33 |
-
image = ""
|
| 34 |
if uploaded_file is not None:
|
| 35 |
-
image=Image.open(uploaded_file)
|
| 36 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
| 37 |
|
| 38 |
submit=st.button("Tell me about the image")
|
| 39 |
|
|
|
|
| 40 |
|
| 41 |
if submit:
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
st.
|
| 45 |
-
|
|
|
|
| 1 |
+
# Q&A Chatbot
|
| 2 |
+
#from langchain.llms import OpenAI
|
| 3 |
+
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
+
load_dotenv() # take environment variables from .env.
|
| 7 |
|
| 8 |
import streamlit as st
|
| 9 |
import os
|
|
|
|
| 11 |
import textwrap
|
| 12 |
from PIL import Image
|
| 13 |
|
| 14 |
+
|
| 15 |
import google.generativeai as genai
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
os.getenv("GOOGLE_API_KEY")
|
| 19 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 20 |
+
|
| 21 |
+
## Function to load OpenAI model and get respones
|
| 22 |
|
| 23 |
+
def get_gemini_response(input,image):
|
| 24 |
model = genai.GenerativeModel('gemini-pro-vision')
|
| 25 |
if input!="":
|
| 26 |
+
response = model.generate_content([input,image])
|
| 27 |
else:
|
| 28 |
+
response = model.generate_content(image)
|
| 29 |
+
return response.text
|
| 30 |
|
| 31 |
+
##initialize our streamlit app
|
| 32 |
|
| 33 |
+
st.set_page_config(page_title="Gemini Image Demo")
|
| 34 |
|
| 35 |
+
st.header("Decoding Data Science Gemini Application")
|
| 36 |
+
input=st.text_input("Input Prompt: ",key="input")
|
| 37 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 38 |
+
image=""
|
|
|
|
| 39 |
if uploaded_file is not None:
|
| 40 |
+
image = Image.open(uploaded_file)
|
| 41 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 42 |
+
|
| 43 |
|
| 44 |
submit=st.button("Tell me about the image")
|
| 45 |
|
| 46 |
+
## If ask button is clicked
|
| 47 |
|
| 48 |
if submit:
|
| 49 |
+
|
| 50 |
+
response=get_gemini_response(input,image)
|
| 51 |
+
st.subheader("The Response is")
|
| 52 |
+
st.write(response)
|