Spaces:
Runtime error
Runtime error
Commit
·
9c0b689
1
Parent(s):
03293e1
Upload 2 files
Browse files- requirements.txt +3 -0
- vision.py +43 -0
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|
vision.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
|
3 |
+
load_dotenv()
|
4 |
+
|
5 |
+
import streamlit as st
|
6 |
+
import os
|
7 |
+
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 |
+
#function to load genai model and get response
|
17 |
+
|
18 |
+
def get_gemini_response(input,image)
|
19 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
20 |
+
if input!="":
|
21 |
+
response = model.generate_content([input,image])
|
22 |
+
else:
|
23 |
+
response = model.generate_content(image)
|
24 |
+
return response.text
|
25 |
+
|
26 |
+
|
27 |
+
##streamlit
|
28 |
+
|
29 |
+
st.header("Decoding Data Science image Recognition Demo")
|
30 |
+
input = st.text_input("Input Prompt", key="input")
|
31 |
+
uploaded_file = st.file_uploader("Choose an Image..", type=["jpg","jpeg","png"])
|
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 |
+
|
39 |
+
if submit:
|
40 |
+
response= get_gemini_response(input,image)
|
41 |
+
st.subheader("The Image Response is")
|
42 |
+
st.write(response)
|
43 |
+
|