Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,7 +99,7 @@ Eres {VOYEUR_SPECIALIST_CONFIG['role']}
|
|
| 99 |
**EXPERIENCIA TÉCNICA:**
|
| 100 |
{expertise}
|
| 101 |
|
| 102 |
-
**
|
| 103 |
{ethics}
|
| 104 |
|
| 105 |
**DIRECTIVAS:**
|
|
@@ -124,13 +124,14 @@ Mantén respuestas concisas y enfocadas.
|
|
| 124 |
"""
|
| 125 |
|
| 126 |
# ==========================
|
| 127 |
-
# FUNCIÓN DE CHAT
|
| 128 |
# ==========================
|
| 129 |
|
| 130 |
def chat_voyeur(message, chat_history, api_key):
|
| 131 |
if not api_key:
|
| 132 |
-
# Formato
|
| 133 |
-
chat_history.append(
|
|
|
|
| 134 |
return "", chat_history
|
| 135 |
|
| 136 |
client = SambaNovaClient(api_key)
|
|
@@ -138,11 +139,9 @@ def chat_voyeur(message, chat_history, api_key):
|
|
| 138 |
# Construir mensajes para la API
|
| 139 |
messages = [{"role": "system", "content": create_voyeur_specialist_system_prompt()}]
|
| 140 |
|
| 141 |
-
# Procesar historial en formato
|
| 142 |
-
for
|
| 143 |
-
messages.append({"role": "
|
| 144 |
-
if assistant_msg and assistant_msg != "❌ Ingresa tu API Key": # Evitar incluir mensajes de error
|
| 145 |
-
messages.append({"role": "assistant", "content": assistant_msg})
|
| 146 |
|
| 147 |
# Agregar el mensaje actual
|
| 148 |
messages.append({"role": "user", "content": message})
|
|
@@ -150,8 +149,10 @@ def chat_voyeur(message, chat_history, api_key):
|
|
| 150 |
# Obtener respuesta
|
| 151 |
response = client.chat_completion(messages)
|
| 152 |
|
| 153 |
-
# Agregar al historial en formato
|
| 154 |
-
chat_history.append(
|
|
|
|
|
|
|
| 155 |
return "", chat_history
|
| 156 |
|
| 157 |
# ==========================
|
|
@@ -170,7 +171,7 @@ def test_sambanova_api(api_key):
|
|
| 170 |
return client.chat_completion(test_messages)
|
| 171 |
|
| 172 |
# ==========================
|
| 173 |
-
# INTERFAZ GRADIO
|
| 174 |
# ==========================
|
| 175 |
|
| 176 |
def create_interface():
|
|
@@ -194,7 +195,7 @@ def create_interface():
|
|
| 194 |
for expertise in VOYEUR_SPECIALIST_CONFIG["technical_expertise"]:
|
| 195 |
gr.Markdown(f"• {expertise}")
|
| 196 |
with gr.Column(scale=2):
|
| 197 |
-
#
|
| 198 |
chatbot = gr.Chatbot(
|
| 199 |
label="💬 Chat con el Especialista",
|
| 200 |
height=500
|
|
@@ -225,10 +226,10 @@ def create_interface():
|
|
| 225 |
outputs=[test_output],
|
| 226 |
)
|
| 227 |
|
| 228 |
-
#
|
| 229 |
def user_message(user_msg, chat_history):
|
| 230 |
-
# Agregar mensaje de usuario
|
| 231 |
-
new_history = chat_history + [
|
| 232 |
return "", new_history
|
| 233 |
|
| 234 |
# Configurar el envío con Enter
|
|
@@ -260,4 +261,5 @@ def create_interface():
|
|
| 260 |
|
| 261 |
if __name__ == "__main__":
|
| 262 |
demo = create_interface()
|
| 263 |
-
|
|
|
|
|
|
| 99 |
**EXPERIENCIA TÉCNICA:**
|
| 100 |
{expertise}
|
| 101 |
|
| 102 |
+
**PRINCIPLOS ÉTICOS:**
|
| 103 |
{ethics}
|
| 104 |
|
| 105 |
**DIRECTIVAS:**
|
|
|
|
| 124 |
"""
|
| 125 |
|
| 126 |
# ==========================
|
| 127 |
+
# FUNCIÓN DE CHAT COMPATIBLE CON HF SPACES
|
| 128 |
# ==========================
|
| 129 |
|
| 130 |
def chat_voyeur(message, chat_history, api_key):
|
| 131 |
if not api_key:
|
| 132 |
+
# Formato de diccionario para HF Spaces
|
| 133 |
+
chat_history.append({"role": "user", "content": message})
|
| 134 |
+
chat_history.append({"role": "assistant", "content": "❌ Ingresa tu API Key"})
|
| 135 |
return "", chat_history
|
| 136 |
|
| 137 |
client = SambaNovaClient(api_key)
|
|
|
|
| 139 |
# Construir mensajes para la API
|
| 140 |
messages = [{"role": "system", "content": create_voyeur_specialist_system_prompt()}]
|
| 141 |
|
| 142 |
+
# Procesar historial en formato diccionario
|
| 143 |
+
for msg in chat_history:
|
| 144 |
+
messages.append({"role": msg["role"], "content": msg["content"]})
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# Agregar el mensaje actual
|
| 147 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 149 |
# Obtener respuesta
|
| 150 |
response = client.chat_completion(messages)
|
| 151 |
|
| 152 |
+
# Agregar al historial en formato diccionario
|
| 153 |
+
chat_history.append({"role": "user", "content": message})
|
| 154 |
+
chat_history.append({"role": "assistant", "content": response})
|
| 155 |
+
|
| 156 |
return "", chat_history
|
| 157 |
|
| 158 |
# ==========================
|
|
|
|
| 171 |
return client.chat_completion(test_messages)
|
| 172 |
|
| 173 |
# ==========================
|
| 174 |
+
# INTERFAZ GRADIO COMPATIBLE CON HF SPACES
|
| 175 |
# ==========================
|
| 176 |
|
| 177 |
def create_interface():
|
|
|
|
| 195 |
for expertise in VOYEUR_SPECIALIST_CONFIG["technical_expertise"]:
|
| 196 |
gr.Markdown(f"• {expertise}")
|
| 197 |
with gr.Column(scale=2):
|
| 198 |
+
# Chatbot sin parámetros problemáticos
|
| 199 |
chatbot = gr.Chatbot(
|
| 200 |
label="💬 Chat con el Especialista",
|
| 201 |
height=500
|
|
|
|
| 226 |
outputs=[test_output],
|
| 227 |
)
|
| 228 |
|
| 229 |
+
# Función para manejar mensajes en formato diccionario
|
| 230 |
def user_message(user_msg, chat_history):
|
| 231 |
+
# Agregar mensaje de usuario al historial
|
| 232 |
+
new_history = chat_history + [{"role": "user", "content": user_msg}]
|
| 233 |
return "", new_history
|
| 234 |
|
| 235 |
# Configurar el envío con Enter
|
|
|
|
| 261 |
|
| 262 |
if __name__ == "__main__":
|
| 263 |
demo = create_interface()
|
| 264 |
+
# CORRECCIÓN: Eliminar share=True para Hugging Face Spaces
|
| 265 |
+
demo.launch(debug=True)
|