Spaces:
Runtime error
Runtime error
Commit
·
1b75933
1
Parent(s):
18bbff5
Update app.py
Browse files
app.py
CHANGED
@@ -25,15 +25,16 @@ if "chat_history" not in st.session_state:
|
|
25 |
st.title("Gemini Chatbot")
|
26 |
|
27 |
# Display the chat history
|
28 |
-
for message in st.session_state.chat_history:
|
29 |
role, text = message
|
30 |
-
|
|
|
31 |
|
32 |
# Text input for the user to send messages
|
33 |
-
user_input = st.text_input("Enter your message here:")
|
34 |
|
35 |
# File uploader for images
|
36 |
-
uploaded_files = st.file_uploader("Upload images:", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
37 |
|
38 |
# Function to convert image to base64
|
39 |
def get_image_base64(image):
|
@@ -43,7 +44,7 @@ def get_image_base64(image):
|
|
43 |
return img_str
|
44 |
|
45 |
# When the 'Send' button is clicked, process the input and generate a response
|
46 |
-
if st.button("Send"):
|
47 |
# Save user input to the chat history if it's not empty
|
48 |
if user_input.strip():
|
49 |
st.session_state.chat_history.append(("user", user_input))
|
@@ -83,7 +84,8 @@ if st.button("Send"):
|
|
83 |
# Save the model response to the chat history
|
84 |
st.session_state.chat_history.append(("model", response_text))
|
85 |
|
86 |
-
#
|
87 |
-
for message in st.session_state.chat_history:
|
88 |
role, text = message
|
89 |
-
|
|
|
|
25 |
st.title("Gemini Chatbot")
|
26 |
|
27 |
# Display the chat history
|
28 |
+
for idx, message in enumerate(st.session_state.chat_history):
|
29 |
role, text = message
|
30 |
+
key = f"message_{idx}_{role}" # Unique key for each message
|
31 |
+
st.text_area(f"{role.title()} says:", value=text, height=75, disabled=True, key=key)
|
32 |
|
33 |
# Text input for the user to send messages
|
34 |
+
user_input = st.text_input("Enter your message here:", key="user_input")
|
35 |
|
36 |
# File uploader for images
|
37 |
+
uploaded_files = st.file_uploader("Upload images:", type=["png", "jpg", "jpeg"], accept_multiple_files=True, key="file_uploader")
|
38 |
|
39 |
# Function to convert image to base64
|
40 |
def get_image_base64(image):
|
|
|
44 |
return img_str
|
45 |
|
46 |
# When the 'Send' button is clicked, process the input and generate a response
|
47 |
+
if st.button("Send", key="send_button"):
|
48 |
# Save user input to the chat history if it's not empty
|
49 |
if user_input.strip():
|
50 |
st.session_state.chat_history.append(("user", user_input))
|
|
|
84 |
# Save the model response to the chat history
|
85 |
st.session_state.chat_history.append(("model", response_text))
|
86 |
|
87 |
+
# Redisplay the updated chat history
|
88 |
+
for idx, message in enumerate(st.session_state.chat_history):
|
89 |
role, text = message
|
90 |
+
key = f"message_{idx}_{role}" # Unique key for each message
|
91 |
+
st.text_area(f"{role.title()} says:", value=text, height=75, disabled=True, key=key)
|