Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def generate(prompt):
|
|
| 69 |
logger.info(f"🔄 Iniciando llamada al API de Hugging Face - {datetime.datetime.now()}")
|
| 70 |
|
| 71 |
generate_kwargs = dict(
|
| 72 |
-
temperature=0.
|
| 73 |
max_new_tokens=800,
|
| 74 |
top_p=0.95,
|
| 75 |
repetition_penalty=1.1,
|
|
@@ -95,11 +95,14 @@ def generate(prompt):
|
|
| 95 |
return f"Lo siento, ocurrió un error durante la interpretación. Detalles: {str(e)}"
|
| 96 |
|
| 97 |
# Reemplazo de variables en documento Word
|
|
|
|
|
|
|
| 98 |
def replace_variables_word(doc, variables):
|
| 99 |
for paragraph in doc.paragraphs:
|
| 100 |
for key, value in variables.items():
|
| 101 |
if f'<{key}>' in paragraph.text:
|
| 102 |
paragraph.text = re.sub(f'<{key}>', value, paragraph.text)
|
|
|
|
| 103 |
for table in doc.tables:
|
| 104 |
for row in table.rows:
|
| 105 |
for cell in row.cells:
|
|
@@ -107,6 +110,7 @@ def replace_variables_word(doc, variables):
|
|
| 107 |
for key, value in variables.items():
|
| 108 |
if f'<{key}>' in paragraph.text:
|
| 109 |
paragraph.text = re.sub(f'<{key}>', value, paragraph.text)
|
|
|
|
| 110 |
|
| 111 |
# Generar documento Word con interpretación
|
| 112 |
def generate_word_document(interpretation):
|
|
@@ -140,7 +144,7 @@ logger.info("🚀 Aplicación iniciada")
|
|
| 140 |
entrada_usuario = st.text_area(
|
| 141 |
"Ingrese respuestas del Test de Rorschach:",
|
| 142 |
height=150,
|
| 143 |
-
placeholder="Ejemplo: Lámina I: Veo un murciélago..."
|
| 144 |
)
|
| 145 |
|
| 146 |
if st.button("Enviar", type="primary"):
|
|
@@ -168,18 +172,18 @@ if st.button("Enviar", type="primary"):
|
|
| 168 |
logger.error("❌ No se pudo generar el documento Word")
|
| 169 |
|
| 170 |
# Mostrar logs en la interfaz (opcional)
|
| 171 |
-
if st.checkbox("Mostrar logs", value=False):
|
| 172 |
-
class StreamlitLogHandler(logging.Handler):
|
| 173 |
-
def emit(self, record):
|
| 174 |
-
log_entry = self.format(record)
|
| 175 |
-
st.code(log_entry)
|
| 176 |
-
|
| 177 |
-
st.subheader("Logs del sistema")
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
stream_handler = StreamlitLogHandler()
|
| 181 |
-
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
logger.info("📊 Visualización de logs activada")
|
| 185 |
-
|
|
|
|
| 69 |
logger.info(f"🔄 Iniciando llamada al API de Hugging Face - {datetime.datetime.now()}")
|
| 70 |
|
| 71 |
generate_kwargs = dict(
|
| 72 |
+
temperature=0.9,
|
| 73 |
max_new_tokens=800,
|
| 74 |
top_p=0.95,
|
| 75 |
repetition_penalty=1.1,
|
|
|
|
| 95 |
return f"Lo siento, ocurrió un error durante la interpretación. Detalles: {str(e)}"
|
| 96 |
|
| 97 |
# Reemplazo de variables en documento Word
|
| 98 |
+
from docx.enum.text import WD_ALIGN_PARAGRAPH # Asegúrate de importar esto arriba
|
| 99 |
+
|
| 100 |
def replace_variables_word(doc, variables):
|
| 101 |
for paragraph in doc.paragraphs:
|
| 102 |
for key, value in variables.items():
|
| 103 |
if f'<{key}>' in paragraph.text:
|
| 104 |
paragraph.text = re.sub(f'<{key}>', value, paragraph.text)
|
| 105 |
+
paragraph.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY # Justificación completa
|
| 106 |
for table in doc.tables:
|
| 107 |
for row in table.rows:
|
| 108 |
for cell in row.cells:
|
|
|
|
| 110 |
for key, value in variables.items():
|
| 111 |
if f'<{key}>' in paragraph.text:
|
| 112 |
paragraph.text = re.sub(f'<{key}>', value, paragraph.text)
|
| 113 |
+
paragraph.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
|
| 114 |
|
| 115 |
# Generar documento Word con interpretación
|
| 116 |
def generate_word_document(interpretation):
|
|
|
|
| 144 |
entrada_usuario = st.text_area(
|
| 145 |
"Ingrese respuestas del Test de Rorschach:",
|
| 146 |
height=150,
|
| 147 |
+
placeholder="Ejemplo: Lámina I: Veo un murciélago sobre un noche estrellada..."
|
| 148 |
)
|
| 149 |
|
| 150 |
if st.button("Enviar", type="primary"):
|
|
|
|
| 172 |
logger.error("❌ No se pudo generar el documento Word")
|
| 173 |
|
| 174 |
# Mostrar logs en la interfaz (opcional)
|
| 175 |
+
#if st.checkbox("Mostrar logs", value=False):
|
| 176 |
+
# class StreamlitLogHandler(logging.Handler):
|
| 177 |
+
# def emit(self, record):
|
| 178 |
+
# log_entry = self.format(record)
|
| 179 |
+
# st.code(log_entry)
|
| 180 |
+
#
|
| 181 |
+
# st.subheader("Logs del sistema")
|
| 182 |
+
# log_output = st.empty()
|
| 183 |
+
#
|
| 184 |
+
# stream_handler = StreamlitLogHandler()
|
| 185 |
+
# stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
|
| 186 |
+
# logger.addHandler(stream_handler)
|
| 187 |
+
|
| 188 |
+
# logger.info("📊 Visualización de logs activada")
|
| 189 |
+
# logger.removeHandler(stream_handler)
|