Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -149,49 +149,46 @@ def procesar_consulta(user_question):
|
|
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
|
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 |
-
#
|
168 |
-
context_es = traducir_contexto(context)
|
169 |
-
|
170 |
prompt_template = """
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
Contexto:
|
176 |
{context}
|
|
|
|
|
|
|
177 |
"""
|
178 |
|
179 |
model = ChatGroq(
|
180 |
-
temperature=0.
|
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=
|
186 |
|
|
|
187 |
preguntas = []
|
188 |
for line in response.content.split("\n"):
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
|
194 |
-
return preguntas[:3]
|
195 |
|
196 |
except Exception as e:
|
197 |
st.error(f"Error generando sugerencias: {str(e)}")
|
@@ -299,4 +296,4 @@ def main():
|
|
299 |
st.write("Por favor, sube un documento para continuar.")
|
300 |
|
301 |
if __name__ == "__main__":
|
302 |
-
main()
|
|
|
149 |
respuesta_final = eliminar_proceso_pensamiento(response['output_text'])
|
150 |
mostrar_respuesta(respuesta_final)
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
def generar_sugerencias():
|
153 |
+
"""Genera preguntas sugeridas usando los chunks más relevantes del documento"""
|
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 |
+
# Prompt para generación de sugerencias
|
|
|
|
|
163 |
prompt_template = """
|
164 |
+
Basado en el siguiente contexto, genera exactamente 3 preguntas relevantes en español.
|
165 |
+
Formato: Cada pregunta debe ser concisa y específica.
|
166 |
+
Las preguntas deben ser útiles para entender el contenido del documento.
|
167 |
|
168 |
Contexto:
|
169 |
{context}
|
170 |
+
|
171 |
+
Preguntas sugeridas:
|
172 |
+
1.
|
173 |
"""
|
174 |
|
175 |
model = ChatGroq(
|
176 |
+
temperature=0.7,
|
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=context))
|
182 |
|
183 |
+
# Procesar la respuesta para extraer las preguntas
|
184 |
preguntas = []
|
185 |
for line in response.content.split("\n"):
|
186 |
+
if line.strip() and any(c.isdigit() for c in line[:3]):
|
187 |
+
pregunta = line.split('.', 1)[1].strip() if '.' in line else line.strip()
|
188 |
+
if pregunta:
|
189 |
+
preguntas.append(pregunta)
|
190 |
|
191 |
+
return preguntas[:3] # Asegurar máximo 3 preguntas
|
192 |
|
193 |
except Exception as e:
|
194 |
st.error(f"Error generando sugerencias: {str(e)}")
|
|
|
296 |
st.write("Por favor, sube un documento para continuar.")
|
297 |
|
298 |
if __name__ == "__main__":
|
299 |
+
main()
|