Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -105,6 +105,8 @@ def main():
|
|
105 |
# Initialize session state
|
106 |
if "chat" not in st.session_state:
|
107 |
st.session_state.chat = model.start_chat(history=[])
|
|
|
|
|
108 |
if "web_search" not in st.session_state:
|
109 |
st.session_state.web_search = False
|
110 |
|
@@ -120,13 +122,16 @@ def main():
|
|
120 |
uploaded_file = st.file_uploader("Télécharger un fichier (image/document)",
|
121 |
type=['jpg', 'mp4', 'mp3', 'jpeg', 'png', 'pdf', 'txt'])
|
122 |
|
123 |
-
# Display chat history
|
124 |
-
for message in st.session_state.
|
125 |
-
with st.chat_message(
|
126 |
-
st.markdown(message
|
127 |
|
128 |
# Chat input
|
129 |
if prompt := st.chat_input("Hey?"):
|
|
|
|
|
|
|
130 |
# Display user message
|
131 |
st.chat_message("user").markdown(prompt)
|
132 |
|
@@ -158,11 +163,8 @@ def main():
|
|
158 |
# Remove the cursor and update with the final response
|
159 |
message_placeholder.markdown(full_response)
|
160 |
|
161 |
-
# Add
|
162 |
-
st.session_state.
|
163 |
-
{"role": "user", "parts": [prompt]},
|
164 |
-
{"role": "model", "parts": [full_response]}
|
165 |
-
])
|
166 |
|
167 |
except Exception as e:
|
168 |
st.error(f"Erreur lors de l'envoi du message : {e}")
|
|
|
105 |
# Initialize session state
|
106 |
if "chat" not in st.session_state:
|
107 |
st.session_state.chat = model.start_chat(history=[])
|
108 |
+
if "messages" not in st.session_state:
|
109 |
+
st.session_state.messages = []
|
110 |
if "web_search" not in st.session_state:
|
111 |
st.session_state.web_search = False
|
112 |
|
|
|
122 |
uploaded_file = st.file_uploader("Télécharger un fichier (image/document)",
|
123 |
type=['jpg', 'mp4', 'mp3', 'jpeg', 'png', 'pdf', 'txt'])
|
124 |
|
125 |
+
# Display chat history from session state
|
126 |
+
for message in st.session_state.messages:
|
127 |
+
with st.chat_message(message["role"]):
|
128 |
+
st.markdown(message["content"])
|
129 |
|
130 |
# Chat input
|
131 |
if prompt := st.chat_input("Hey?"):
|
132 |
+
# Add user message to chat history
|
133 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
134 |
+
|
135 |
# Display user message
|
136 |
st.chat_message("user").markdown(prompt)
|
137 |
|
|
|
163 |
# Remove the cursor and update with the final response
|
164 |
message_placeholder.markdown(full_response)
|
165 |
|
166 |
+
# Add assistant response to chat history
|
167 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
|
|
|
|
168 |
|
169 |
except Exception as e:
|
170 |
st.error(f"Erreur lors de l'envoi du message : {e}")
|