BATUTO-ART commited on
Commit
dcbcd2e
·
verified ·
1 Parent(s): 6f2a908

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -22
app.py CHANGED
@@ -1,5 +1,3 @@
1
- # app.py
2
-
3
  import os
4
  import gradio as gr
5
  import requests
@@ -126,26 +124,34 @@ Mantén respuestas concisas y enfocadas.
126
  """
127
 
128
  # ==========================
129
- # FUNCIÓN DE CHAT
130
  # ==========================
131
 
132
- def chat_voyeur(message, history, api_key):
133
  if not api_key:
134
- return "❌ Ingresa tu API Key", history
 
 
135
 
136
  client = SambaNovaClient(api_key)
 
 
137
  messages = [{"role": "system", "content": create_voyeur_specialist_system_prompt()}]
138
- for user_msg, assistant_msg in history:
 
 
139
  messages.append({"role": "user", "content": user_msg})
140
- if assistant_msg is not None:
141
  messages.append({"role": "assistant", "content": assistant_msg})
142
-
 
143
  messages.append({"role": "user", "content": message})
144
 
145
  response = client.chat_completion(messages)
146
 
147
- history.append([message, response])
148
- return "", history
 
149
 
150
  # ==========================
151
  # PRUEBA DE API
@@ -163,11 +169,10 @@ def test_sambanova_api(api_key):
163
  return client.chat_completion(test_messages)
164
 
165
  # ==========================
166
- # INTERFAZ GRADIO
167
  # ==========================
168
 
169
  def create_interface():
170
- # CORRECCIÓN: Eliminado el parámetro 'theme' que no es compatible
171
  with gr.Blocks(title="Chatbot Voyeur Prompt Specialist") as demo:
172
  gr.Markdown("# 🎭 Chatbot Universal - Especialista en Prompts Sensuales Voyeur")
173
  gr.Markdown("### Conversa en español. Pide prompts sensuales para generarlos en inglés (solo el prompt, fácil de copiar).")
@@ -188,7 +193,7 @@ def create_interface():
188
  for expertise in VOYEUR_SPECIALIST_CONFIG["technical_expertise"]:
189
  gr.Markdown(f"• {expertise}")
190
  with gr.Column(scale=2):
191
- # CORRECCIÓN: Eliminado el parámetro 'show_copy_button' que no es compatible
192
  chatbot = gr.Chatbot(
193
  label="💬 Chat con el Especialista",
194
  height=500
@@ -219,33 +224,40 @@ def create_interface():
219
  outputs=[test_output],
220
  )
221
 
222
- def user_message(user_msg, history):
223
- return "", history + [[user_msg, None]]
 
 
224
 
225
- submit_fn = user_message
226
- then_fn = chat_voyeur
 
 
227
 
 
228
  msg.submit(
229
- submit_fn,
230
  inputs=[msg, chatbot],
231
  outputs=[msg, chatbot],
232
  ).then(
233
- then_fn,
234
  inputs=[msg, chatbot, api_key_input],
235
  outputs=[msg, chatbot],
236
  )
237
 
 
238
  send_btn.click(
239
- submit_fn,
240
  inputs=[msg, chatbot],
241
  outputs=[msg, chatbot],
242
  ).then(
243
- then_fn,
244
  inputs=[msg, chatbot, api_key_input],
245
  outputs=[msg, chatbot],
246
  )
247
 
248
- clear_btn.click(lambda: None, None, chatbot, queue=False)
 
249
 
250
  return demo
251
 
 
 
 
1
  import os
2
  import gradio as gr
3
  import requests
 
124
  """
125
 
126
  # ==========================
127
+ # FUNCIÓN DE CHAT CORREGIDA
128
  # ==========================
129
 
130
+ def chat_voyeur(message, chat_history, api_key):
131
  if not api_key:
132
+ # CORRECCIÓN: Retornar el historial actualizado correctamente
133
+ chat_history.append((message, "❌ Ingresa tu API Key"))
134
+ return "", chat_history
135
 
136
  client = SambaNovaClient(api_key)
137
+
138
+ # CORRECCIÓN: Construir mensajes correctamente
139
  messages = [{"role": "system", "content": create_voyeur_specialist_system_prompt()}]
140
+
141
+ # CORRECCIÓN: Procesar el historial en el formato correcto
142
+ for user_msg, assistant_msg in chat_history:
143
  messages.append({"role": "user", "content": user_msg})
144
+ if assistant_msg: # Solo agregar si no está vacío
145
  messages.append({"role": "assistant", "content": assistant_msg})
146
+
147
+ # Agregar el mensaje actual
148
  messages.append({"role": "user", "content": message})
149
 
150
  response = client.chat_completion(messages)
151
 
152
+ # CORRECCIÓN: Agregar al historial en el formato correcto (tupla)
153
+ chat_history.append((message, response))
154
+ return "", chat_history
155
 
156
  # ==========================
157
  # PRUEBA DE API
 
169
  return client.chat_completion(test_messages)
170
 
171
  # ==========================
172
+ # INTERFAZ GRADIO CORREGIDA
173
  # ==========================
174
 
175
  def create_interface():
 
176
  with gr.Blocks(title="Chatbot Voyeur Prompt Specialist") as demo:
177
  gr.Markdown("# 🎭 Chatbot Universal - Especialista en Prompts Sensuales Voyeur")
178
  gr.Markdown("### Conversa en español. Pide prompts sensuales para generarlos en inglés (solo el prompt, fácil de copiar).")
 
193
  for expertise in VOYEUR_SPECIALIST_CONFIG["technical_expertise"]:
194
  gr.Markdown(f"• {expertise}")
195
  with gr.Column(scale=2):
196
+ # CORRECCIÓN: Usar el formato correcto para el chatbot
197
  chatbot = gr.Chatbot(
198
  label="💬 Chat con el Especialista",
199
  height=500
 
224
  outputs=[test_output],
225
  )
226
 
227
+ # CORRECCIÓN: Función simplificada para manejar mensajes de usuario
228
+ def user_message(user_msg, chat_history):
229
+ # Retornar mensaje vacío y el historial actualizado
230
+ return "", chat_history + [[user_msg, None]]
231
 
232
+ # CORRECCIÓN: Configurar los eventos correctamente
233
+ def respond(message, chat_history, api_key):
234
+ # Función wrapper para mantener compatibilidad
235
+ return chat_voyeur(message, chat_history, api_key)
236
 
237
+ # Configurar el envío con Enter
238
  msg.submit(
239
+ user_message,
240
  inputs=[msg, chatbot],
241
  outputs=[msg, chatbot],
242
  ).then(
243
+ respond,
244
  inputs=[msg, chatbot, api_key_input],
245
  outputs=[msg, chatbot],
246
  )
247
 
248
+ # Configurar el botón Enviar
249
  send_btn.click(
250
+ user_message,
251
  inputs=[msg, chatbot],
252
  outputs=[msg, chatbot],
253
  ).then(
254
+ respond,
255
  inputs=[msg, chatbot, api_key_input],
256
  outputs=[msg, chatbot],
257
  )
258
 
259
+ # Configurar el botón Limpiar
260
+ clear_btn.click(lambda: [], None, chatbot, queue=False)
261
 
262
  return demo
263