Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,25 @@ st.set_page_config(
|
|
14 |
initial_sidebar_state="expanded",
|
15 |
)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Funci贸n para guardar el historial en cookies
|
18 |
def save_chat_history(history):
|
19 |
serializable_history = []
|
@@ -78,7 +97,6 @@ if selected == "System Prompt":
|
|
78 |
|
79 |
if st.button("Guardar System Prompt y URLs"):
|
80 |
st.session_state.system_prompt = new_system_prompt
|
81 |
-
st.session_state.cookie_system_prompt = new_system_prompt
|
82 |
st.session_state.cookie_urls = [url.strip() for url in urls_input.split(",") if url.strip()] # Guardar las URLs en una lista
|
83 |
if "chat_session" in st.session_state:
|
84 |
del st.session_state.chat_session
|
@@ -95,7 +113,7 @@ if selected == "System Prompt":
|
|
95 |
elif selected == "Chatbot":
|
96 |
model = load_gemini_pro()
|
97 |
|
98 |
-
|
99 |
if "chat_session" not in st.session_state:
|
100 |
loaded_chat = load_chat_history()
|
101 |
if loaded_chat:
|
@@ -116,7 +134,7 @@ elif selected == "Chatbot":
|
|
116 |
with st.chat_message(translate_role_to_streamlit(message.role)):
|
117 |
st.markdown(message.parts[0].text)
|
118 |
|
119 |
-
|
120 |
user_prompt = st.chat_input("Preguntame algo...")
|
121 |
if user_prompt:
|
122 |
st.chat_message("user").markdown(user_prompt)
|
@@ -134,7 +152,6 @@ elif selected == "Chatbot":
|
|
134 |
|
135 |
# Aqu铆 puedes procesar el contenido obtenido de las URLs
|
136 |
# Por ejemplo, podr铆as resumirlo o extraer informaci贸n relevante
|
137 |
-
# Para este ejemplo, simplemente unimos el contenido
|
138 |
combined_content = "\n\n".join(fetched_contents)
|
139 |
user_prompt += f"\n\nInformaci贸n adicional de URLs:\n{combined_content}"
|
140 |
|
@@ -172,6 +189,3 @@ elif selected == "Image Captioning":
|
|
172 |
|
173 |
# Fin del script
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
14 |
initial_sidebar_state="expanded",
|
15 |
)
|
16 |
|
17 |
+
# Men煤 de opciones
|
18 |
+
selected = option_menu(
|
19 |
+
menu_title="Men煤",
|
20 |
+
options=["System Prompt", "Chatbot", "Image Captioning"],
|
21 |
+
icons=["gear", "chat", "camera"],
|
22 |
+
default_index=0,
|
23 |
+
orientation="horizontal"
|
24 |
+
)
|
25 |
+
|
26 |
+
# Inicializar el estado de la sesi贸n
|
27 |
+
if 'cookie_chat_history' not in st.session_state:
|
28 |
+
st.session_state.cookie_chat_history = json.dumps([])
|
29 |
+
|
30 |
+
if 'cookie_urls' not in st.session_state:
|
31 |
+
st.session_state.cookie_urls = []
|
32 |
+
|
33 |
+
if 'system_prompt' not in st.session_state:
|
34 |
+
st.session_state.system_prompt = ""
|
35 |
+
|
36 |
# Funci贸n para guardar el historial en cookies
|
37 |
def save_chat_history(history):
|
38 |
serializable_history = []
|
|
|
97 |
|
98 |
if st.button("Guardar System Prompt y URLs"):
|
99 |
st.session_state.system_prompt = new_system_prompt
|
|
|
100 |
st.session_state.cookie_urls = [url.strip() for url in urls_input.split(",") if url.strip()] # Guardar las URLs en una lista
|
101 |
if "chat_session" in st.session_state:
|
102 |
del st.session_state.chat_session
|
|
|
113 |
elif selected == "Chatbot":
|
114 |
model = load_gemini_pro()
|
115 |
|
116 |
+
# Inicializar o cargar sesi贸n de chat
|
117 |
if "chat_session" not in st.session_state:
|
118 |
loaded_chat = load_chat_history()
|
119 |
if loaded_chat:
|
|
|
134 |
with st.chat_message(translate_role_to_streamlit(message.role)):
|
135 |
st.markdown(message.parts[0].text)
|
136 |
|
137 |
+
# Campo de entrada
|
138 |
user_prompt = st.chat_input("Preguntame algo...")
|
139 |
if user_prompt:
|
140 |
st.chat_message("user").markdown(user_prompt)
|
|
|
152 |
|
153 |
# Aqu铆 puedes procesar el contenido obtenido de las URLs
|
154 |
# Por ejemplo, podr铆as resumirlo o extraer informaci贸n relevante
|
|
|
155 |
combined_content = "\n\n".join(fetched_contents)
|
156 |
user_prompt += f"\n\nInformaci贸n adicional de URLs:\n{combined_content}"
|
157 |
|
|
|
189 |
|
190 |
# Fin del script
|
191 |
|
|
|
|
|
|