Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
|
@@ -126,22 +124,25 @@ Mantén respuestas concisas y enfocadas.
|
|
| 126 |
"""
|
| 127 |
|
| 128 |
# ==========================
|
| 129 |
-
# FUNCIÓN DE CHAT CORREGIDA
|
| 130 |
# ==========================
|
| 131 |
|
| 132 |
def chat_voyeur(message, chat_history, api_key):
|
| 133 |
if not api_key:
|
| 134 |
-
#
|
| 135 |
-
|
|
|
|
| 136 |
|
| 137 |
client = SambaNovaClient(api_key)
|
| 138 |
|
| 139 |
# Construir mensajes para la API
|
| 140 |
messages = [{"role": "system", "content": create_voyeur_specialist_system_prompt()}]
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
for
|
| 144 |
-
messages.append({"role":
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# Agregar el mensaje actual
|
| 147 |
messages.append({"role": "user", "content": message})
|
|
@@ -149,13 +150,9 @@ def chat_voyeur(message, chat_history, api_key):
|
|
| 149 |
# Obtener respuesta
|
| 150 |
response = client.chat_completion(messages)
|
| 151 |
|
| 152 |
-
#
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
{"role": "assistant", "content": response}
|
| 156 |
-
]
|
| 157 |
-
|
| 158 |
-
return "", updated_history
|
| 159 |
|
| 160 |
# ==========================
|
| 161 |
# PRUEBA DE API
|
|
@@ -197,11 +194,10 @@ def create_interface():
|
|
| 197 |
for expertise in VOYEUR_SPECIALIST_CONFIG["technical_expertise"]:
|
| 198 |
gr.Markdown(f"• {expertise}")
|
| 199 |
with gr.Column(scale=2):
|
| 200 |
-
# CORRECCIÓN:
|
| 201 |
chatbot = gr.Chatbot(
|
| 202 |
label="💬 Chat con el Especialista",
|
| 203 |
-
height=500
|
| 204 |
-
type="messages" # Especificar que usamos formato de mensajes
|
| 205 |
)
|
| 206 |
msg = gr.Textbox(
|
| 207 |
label="Escribe tu mensaje",
|
|
@@ -229,10 +225,10 @@ def create_interface():
|
|
| 229 |
outputs=[test_output],
|
| 230 |
)
|
| 231 |
|
| 232 |
-
# CORRECCIÓN: Función
|
| 233 |
def user_message(user_msg, chat_history):
|
| 234 |
-
# Agregar mensaje de usuario
|
| 235 |
-
new_history = chat_history + [
|
| 236 |
return "", new_history
|
| 237 |
|
| 238 |
# Configurar el envío con Enter
|
|
@@ -257,7 +253,7 @@ def create_interface():
|
|
| 257 |
outputs=[msg, chatbot],
|
| 258 |
)
|
| 259 |
|
| 260 |
-
#
|
| 261 |
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 262 |
|
| 263 |
return demo
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 124 |
"""
|
| 125 |
|
| 126 |
# ==========================
|
| 127 |
+
# FUNCIÓN DE CHAT CORREGIDA (formato tuplas)
|
| 128 |
# ==========================
|
| 129 |
|
| 130 |
def chat_voyeur(message, chat_history, api_key):
|
| 131 |
if not api_key:
|
| 132 |
+
# Formato tuplas para versiones antiguas de Gradio
|
| 133 |
+
chat_history.append((message, "❌ Ingresa tu API Key"))
|
| 134 |
+
return "", chat_history
|
| 135 |
|
| 136 |
client = SambaNovaClient(api_key)
|
| 137 |
|
| 138 |
# Construir mensajes para la API
|
| 139 |
messages = [{"role": "system", "content": create_voyeur_specialist_system_prompt()}]
|
| 140 |
|
| 141 |
+
# Procesar historial en formato tuplas
|
| 142 |
+
for user_msg, assistant_msg in chat_history:
|
| 143 |
+
messages.append({"role": "user", "content": user_msg})
|
| 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 |
# Obtener respuesta
|
| 151 |
response = client.chat_completion(messages)
|
| 152 |
|
| 153 |
+
# Agregar al historial en formato tuplas
|
| 154 |
+
chat_history.append((message, response))
|
| 155 |
+
return "", chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
# ==========================
|
| 158 |
# PRUEBA DE API
|
|
|
|
| 194 |
for expertise in VOYEUR_SPECIALIST_CONFIG["technical_expertise"]:
|
| 195 |
gr.Markdown(f"• {expertise}")
|
| 196 |
with gr.Column(scale=2):
|
| 197 |
+
# CORRECCIÓN: Sin parámetro 'type' para compatibilidad
|
| 198 |
chatbot = gr.Chatbot(
|
| 199 |
label="💬 Chat con el Especialista",
|
| 200 |
+
height=500
|
|
|
|
| 201 |
)
|
| 202 |
msg = gr.Textbox(
|
| 203 |
label="Escribe tu mensaje",
|
|
|
|
| 225 |
outputs=[test_output],
|
| 226 |
)
|
| 227 |
|
| 228 |
+
# CORRECCIÓN: Función para manejar mensajes en formato tuplas
|
| 229 |
def user_message(user_msg, chat_history):
|
| 230 |
+
# Agregar mensaje de usuario con None como respuesta temporal
|
| 231 |
+
new_history = chat_history + [[user_msg, None]]
|
| 232 |
return "", new_history
|
| 233 |
|
| 234 |
# Configurar el envío con Enter
|
|
|
|
| 253 |
outputs=[msg, chatbot],
|
| 254 |
)
|
| 255 |
|
| 256 |
+
# Configurar el botón Limpiar
|
| 257 |
clear_btn.click(lambda: [], None, chatbot, queue=False)
|
| 258 |
|
| 259 |
return demo
|