Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,13 @@ def load_chat_history():
|
|
40 |
st.error(f"Error cargando el historial: {e}")
|
41 |
return None
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# Inicializar estados
|
44 |
if "system_prompt" not in st.session_state:
|
45 |
st.session_state.system_prompt = st.session_state.get('cookie_system_prompt', "")
|
@@ -109,7 +116,7 @@ elif selected == "Chatbot":
|
|
109 |
with st.chat_message(translate_role_to_streamlit(message.role)):
|
110 |
st.markdown(message.parts[0].text)
|
111 |
|
112 |
-
|
113 |
user_prompt = st.chat_input("Preguntame algo...")
|
114 |
if user_prompt:
|
115 |
st.chat_message("user").markdown(user_prompt)
|
@@ -120,6 +127,16 @@ elif selected == "Chatbot":
|
|
120 |
# Guardar historial actualizado
|
121 |
save_chat_history(st.session_state.chat_session.history)
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
elif selected == "Image Captioning":
|
124 |
st.title("Image Caption Generation馃摳")
|
125 |
upload_image = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
@@ -132,4 +149,6 @@ elif selected == "Image Captioning":
|
|
132 |
default_prompt = "Write a caption for this image"
|
133 |
caption = gemini_pro_vision_responce(default_prompt, image)
|
134 |
with col2:
|
135 |
-
st.info(caption)
|
|
|
|
|
|
40 |
st.error(f"Error cargando el historial: {e}")
|
41 |
return None
|
42 |
|
43 |
+
# Funci贸n para descargar el historial del chat
|
44 |
+
def download_chat_history(history):
|
45 |
+
chat_text = ""
|
46 |
+
for message in history:
|
47 |
+
chat_text += f"{message.role}: {message.parts[0].text}\n"
|
48 |
+
return chat_text
|
49 |
+
|
50 |
# Inicializar estados
|
51 |
if "system_prompt" not in st.session_state:
|
52 |
st.session_state.system_prompt = st.session_state.get('cookie_system_prompt', "")
|
|
|
116 |
with st.chat_message(translate_role_to_streamlit(message.role)):
|
117 |
st.markdown(message.parts[0].text)
|
118 |
|
119 |
+
# Campo de entrada
|
120 |
user_prompt = st.chat_input("Preguntame algo...")
|
121 |
if user_prompt:
|
122 |
st.chat_message("user").markdown(user_prompt)
|
|
|
127 |
# Guardar historial actualizado
|
128 |
save_chat_history(st.session_state.chat_session.history)
|
129 |
|
130 |
+
# Opci贸n para descargar el historial del chat
|
131 |
+
if st.button("Descargar Historial del Chat"):
|
132 |
+
chat_history = download_chat_history(st.session_state.chat_session.history)
|
133 |
+
st.download_button(
|
134 |
+
label="Descargar",
|
135 |
+
data=chat_history,
|
136 |
+
file_name="historial_chat.txt",
|
137 |
+
mime="text/plain"
|
138 |
+
)
|
139 |
+
|
140 |
elif selected == "Image Captioning":
|
141 |
st.title("Image Caption Generation馃摳")
|
142 |
upload_image = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
|
|
149 |
default_prompt = "Write a caption for this image"
|
150 |
caption = gemini_pro_vision_responce(default_prompt, image)
|
151 |
with col2:
|
152 |
+
st.info(caption)
|
153 |
+
|
154 |
+
# Fin del script
|