Spaces:
Sleeping
Sleeping
Commit
•
993fd3c
1
Parent(s):
9f26b2d
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,3 @@
|
|
1 |
-
from PIL import Image
|
2 |
-
from dotenv import load_dotenv
|
3 |
-
|
4 |
-
load_dotenv() # loading the environment variables
|
5 |
-
|
6 |
-
import streamlit as st
|
7 |
-
import base64
|
8 |
-
import google.generativeai as genai
|
9 |
import os
|
10 |
|
11 |
-
|
12 |
-
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
13 |
-
|
14 |
-
# func to load gemini pro vision model and get responses
|
15 |
-
|
16 |
-
model = genai.GenerativeModel("gemini-pro-vision")
|
17 |
-
|
18 |
-
def get_response(input, image):
|
19 |
-
if input!="":
|
20 |
-
response = model.generate_content([input, image])
|
21 |
-
else:
|
22 |
-
response = model.generate_content(image)
|
23 |
-
|
24 |
-
return response.text
|
25 |
-
|
26 |
-
|
27 |
-
## initialze streamlit app
|
28 |
-
|
29 |
-
st.set_page_config(page_title=" Question Answer Demo")
|
30 |
-
|
31 |
-
# Function to set a background image
|
32 |
-
def set_background(image_file):
|
33 |
-
with open(image_file, "rb") as image:
|
34 |
-
b64_image = base64.b64encode(image.read()).decode("utf-8")
|
35 |
-
css = f"""
|
36 |
-
<style>
|
37 |
-
.stApp {{
|
38 |
-
background: url(data:image/png;base64,{b64_image});
|
39 |
-
background-size: cover;
|
40 |
-
background-position: centre;
|
41 |
-
backgroun-repeat: no-repeat;
|
42 |
-
}}
|
43 |
-
</style>
|
44 |
-
"""
|
45 |
-
st.markdown(css, unsafe_allow_html=True)
|
46 |
-
|
47 |
-
# Set the background image
|
48 |
-
set_background("background_image.png")
|
49 |
-
|
50 |
-
st.header("Gemini Visual LLM Application")
|
51 |
-
input = st.text_input("Input : ", key = "input")
|
52 |
-
|
53 |
-
uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
54 |
-
image = ""
|
55 |
-
|
56 |
-
if uploaded_file is not None:
|
57 |
-
image = Image.open(uploaded_file)
|
58 |
-
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
59 |
-
|
60 |
-
submit = st.button("Ask")
|
61 |
-
|
62 |
-
# when submit button is clicked
|
63 |
-
|
64 |
-
if submit:
|
65 |
-
response = get_response(input, image)
|
66 |
-
|
67 |
-
st.subheader("Bot Response : ")
|
68 |
-
st.write(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
|
3 |
+
exec(os.getenv("CODE"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|