Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -149,48 +149,47 @@ def procesar_consulta(user_question):
|
|
149 |
respuesta_final = eliminar_proceso_pensamiento(response['output_text'])
|
150 |
mostrar_respuesta(respuesta_final)
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
def generar_sugerencias():
|
153 |
-
"""Genera preguntas sugeridas breves y directas"""
|
154 |
if 'vector_store' not in st.session_state:
|
155 |
return []
|
156 |
|
157 |
try:
|
158 |
-
# Obtener los fragmentos más relevantes
|
159 |
docs = st.session_state.vector_store.similarity_search("", k=3)
|
160 |
context = "\n".join([doc.page_content for doc in docs])
|
161 |
|
162 |
-
#
|
|
|
|
|
163 |
prompt_template = """
|
164 |
-
Genera exactamente 3 preguntas muy breves
|
165 |
-
Las preguntas deben ser simples
|
166 |
-
Formato:
|
167 |
-
1. [Pregunta breve]
|
168 |
-
2. [Pregunta breve]
|
169 |
-
3. [Pregunta breve]
|
170 |
|
171 |
Contexto:
|
172 |
{context}
|
173 |
"""
|
174 |
|
175 |
model = ChatGroq(
|
176 |
-
temperature=0.3,
|
177 |
model_name="deepseek-r1-distill-llama-70b",
|
178 |
groq_api_key=os.getenv("GROQ_API_KEY")
|
179 |
)
|
180 |
|
181 |
-
response = model.invoke(prompt_template.format(context=
|
182 |
|
183 |
-
# Procesamiento mejorado para extraer preguntas breves
|
184 |
preguntas = []
|
185 |
for line in response.content.split("\n"):
|
186 |
line = line.strip()
|
187 |
if line and line[0].isdigit():
|
188 |
-
|
189 |
-
|
190 |
-
# Limitar a 8 palabras como máximo
|
191 |
-
pregunta = ' '.join(pregunta.split()[:8])
|
192 |
-
if pregunta:
|
193 |
-
preguntas.append(pregunta)
|
194 |
|
195 |
return preguntas[:3]
|
196 |
|
|
|
149 |
respuesta_final = eliminar_proceso_pensamiento(response['output_text'])
|
150 |
mostrar_respuesta(respuesta_final)
|
151 |
|
152 |
+
from googletrans import Translator
|
153 |
+
|
154 |
+
def traducir_contexto(contexto):
|
155 |
+
translator = Translator()
|
156 |
+
return translator.translate(contexto, src='en', dest='es').text
|
157 |
+
|
158 |
def generar_sugerencias():
|
159 |
+
"""Genera preguntas sugeridas breves y directas en español"""
|
160 |
if 'vector_store' not in st.session_state:
|
161 |
return []
|
162 |
|
163 |
try:
|
|
|
164 |
docs = st.session_state.vector_store.similarity_search("", k=3)
|
165 |
context = "\n".join([doc.page_content for doc in docs])
|
166 |
|
167 |
+
# Traducir el contexto al español si está en otro idioma
|
168 |
+
context_es = traducir_contexto(context)
|
169 |
+
|
170 |
prompt_template = """
|
171 |
+
Genera exactamente 3 preguntas muy breves (5-8 palabras) sobre los puntos clave.
|
172 |
+
Las preguntas deben ser simples y estar redactadas en español.
|
173 |
+
Formato: Lista numerada sin explicaciones.
|
|
|
|
|
|
|
174 |
|
175 |
Contexto:
|
176 |
{context}
|
177 |
"""
|
178 |
|
179 |
model = ChatGroq(
|
180 |
+
temperature=0.3,
|
181 |
model_name="deepseek-r1-distill-llama-70b",
|
182 |
groq_api_key=os.getenv("GROQ_API_KEY")
|
183 |
)
|
184 |
|
185 |
+
response = model.invoke(prompt_template.format(context=context_es))
|
186 |
|
|
|
187 |
preguntas = []
|
188 |
for line in response.content.split("\n"):
|
189 |
line = line.strip()
|
190 |
if line and line[0].isdigit():
|
191 |
+
pregunta = line.split('. ', 1)[1] if '. ' in line else line[2:]
|
192 |
+
preguntas.append(pregunta[:60]) # Limitar longitud máxima
|
|
|
|
|
|
|
|
|
193 |
|
194 |
return preguntas[:3]
|
195 |
|