Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,12 @@ from langchain_google_genai import ChatGoogleGenerativeAI
|
|
8 |
from datetime import datetime
|
9 |
from langchain_core.messages import HumanMessage
|
10 |
|
|
|
|
|
11 |
os.environ["GOOGLE_API_KEY"] = "AIzaSyAc0VslmJlmiTFx7GB8QPYEHUZ5nZb5_Nk"
|
12 |
st.title("Vision Bot")
|
13 |
|
|
|
14 |
llm = ChatGoogleGenerativeAI(
|
15 |
model="gemini-1.5-flash",
|
16 |
max_tokens=4000
|
@@ -23,15 +26,26 @@ if not os.path.exists(IMAGE_SAVE_FOLDER):
|
|
23 |
st.markdown(
|
24 |
"""
|
25 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
.st-emotion-cache-janbn0 {
|
27 |
flex-direction: row-reverse;
|
28 |
text-align: right;
|
29 |
}
|
|
|
|
|
|
|
|
|
|
|
30 |
</style>
|
31 |
""",
|
32 |
unsafe_allow_html=True,
|
33 |
)
|
34 |
-
|
35 |
# Initialize session states
|
36 |
if "messages" not in st.session_state:
|
37 |
st.session_state.messages = []
|
@@ -45,14 +59,32 @@ if "last_displayed_image" not in st.session_state:
|
|
45 |
st.session_state.last_displayed_image = None
|
46 |
|
47 |
container = st.container()
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# Upload image
|
50 |
-
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"], key="image_uploader")
|
51 |
|
52 |
# Check if a new image is uploaded
|
53 |
if uploaded_image and uploaded_image != st.session_state.current_image:
|
54 |
st.session_state.current_image = uploaded_image
|
55 |
-
|
|
|
|
|
56 |
|
57 |
# Add a system message to mark the new image in the conversation
|
58 |
st.session_state.messages.append({
|
@@ -65,7 +97,8 @@ if uploaded_image and uploaded_image != st.session_state.current_image:
|
|
65 |
for message in st.session_state.messages:
|
66 |
with container.chat_message(message["role"]):
|
67 |
if message["role"] == "system" and "image" in message:
|
68 |
-
|
|
|
69 |
st.write(message["content"])
|
70 |
|
71 |
# Take prompt
|
|
|
8 |
from datetime import datetime
|
9 |
from langchain_core.messages import HumanMessage
|
10 |
|
11 |
+
# Define title and layout
|
12 |
+
st.set_page_config(page_title="Vision Bot", layout="wide")
|
13 |
os.environ["GOOGLE_API_KEY"] = "AIzaSyAc0VslmJlmiTFx7GB8QPYEHUZ5nZb5_Nk"
|
14 |
st.title("Vision Bot")
|
15 |
|
16 |
+
|
17 |
llm = ChatGoogleGenerativeAI(
|
18 |
model="gemini-1.5-flash",
|
19 |
max_tokens=4000
|
|
|
26 |
st.markdown(
|
27 |
"""
|
28 |
<style>
|
29 |
+
.sidebar-content {
|
30 |
+
background-color: #f1f3f6;
|
31 |
+
padding: 20px;
|
32 |
+
border-radius: 10px;
|
33 |
+
text-align: left;
|
34 |
+
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
|
35 |
+
}
|
36 |
.st-emotion-cache-janbn0 {
|
37 |
flex-direction: row-reverse;
|
38 |
text-align: right;
|
39 |
}
|
40 |
+
.uploaded-image {
|
41 |
+
border: 2px solid #D1D1D1;
|
42 |
+
border-radius: 8px;
|
43 |
+
margin-top: 10px;
|
44 |
+
}
|
45 |
</style>
|
46 |
""",
|
47 |
unsafe_allow_html=True,
|
48 |
)
|
|
|
49 |
# Initialize session states
|
50 |
if "messages" not in st.session_state:
|
51 |
st.session_state.messages = []
|
|
|
59 |
st.session_state.last_displayed_image = None
|
60 |
|
61 |
container = st.container()
|
62 |
+
with st.sidebar:
|
63 |
+
st.markdown(
|
64 |
+
"""
|
65 |
+
<div class="sidebar-content">
|
66 |
+
<h2>Vision Bot</h2>
|
67 |
+
<p>This is Vision Bot where you can ask any question regarding any image. It can perform various tasks such as:</p>
|
68 |
+
<ul>
|
69 |
+
<li><b>Image Captioning</b></li>
|
70 |
+
<li><b>Answering text-related queries inside the image</b></li>
|
71 |
+
<li><b>OCR (Optical Character Recognition)</b></li>
|
72 |
+
<li><b>Image Analysis & Description</b></li>
|
73 |
+
</ul>
|
74 |
+
</div>
|
75 |
+
""",
|
76 |
+
unsafe_allow_html=True,
|
77 |
+
)
|
78 |
+
# Upload image
|
79 |
# Upload image
|
80 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png","webp"], key="image_uploader")
|
81 |
|
82 |
# Check if a new image is uploaded
|
83 |
if uploaded_image and uploaded_image != st.session_state.current_image:
|
84 |
st.session_state.current_image = uploaded_image
|
85 |
+
|
86 |
+
# Fix image size here
|
87 |
+
st.image(uploaded_image, caption="Newly Uploaded Image", width=300) # Adjust width to a smaller size
|
88 |
|
89 |
# Add a system message to mark the new image in the conversation
|
90 |
st.session_state.messages.append({
|
|
|
97 |
for message in st.session_state.messages:
|
98 |
with container.chat_message(message["role"]):
|
99 |
if message["role"] == "system" and "image" in message:
|
100 |
+
# Display image in chat history with fixed size
|
101 |
+
st.image(message["image"], width=300) # Adjust width to a smaller size
|
102 |
st.write(message["content"])
|
103 |
|
104 |
# Take prompt
|