Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,123 +71,92 @@ def mejorar_texto_con_IA(var_name, var_value, vectordb_list, nombre_curso):
|
|
| 71 |
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def crear_documento(nombre_curso, variables):
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Título Principal
|
| 79 |
titulo = doc.add_paragraph()
|
| 80 |
-
titulo.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
| 81 |
titulo_run = titulo.add_run("PROGRAMA OFICIAL DE CURSO\n(Pregrado y Posgrado)\nUNIVERSIDAD DE ANTIOQUIA")
|
| 82 |
titulo_run.bold = True
|
| 83 |
titulo_run.font.size = Pt(16)
|
| 84 |
-
titulo_run.font.color.rgb = RGBColor(34, 85, 85) #
|
| 85 |
-
|
| 86 |
-
# Información General - Título de sección
|
| 87 |
-
titulo_info_general = doc.add_paragraph("INFORMACIÓN GENERAL")
|
| 88 |
-
titulo_info_general.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
|
| 89 |
-
titulo_info_general.style = 'Heading 1' # Asumiendo que este estilo existe en la plantilla
|
| 90 |
-
for run in titulo_info_general.runs:
|
| 91 |
-
run.font.color.rgb = RGBColor(34, 85, 85)
|
| 92 |
-
|
| 93 |
# Información General - Tabla
|
|
|
|
| 94 |
info_table = doc.add_table(rows=0, cols=2)
|
| 95 |
-
info_table.style = 'Table Grid'
|
| 96 |
-
|
| 97 |
info_general = [
|
| 98 |
("Nombre del curso", nombre_curso),
|
| 99 |
-
("Programa académico", str(variables.get('programa_academico', ''))),
|
| 100 |
-
("Unidad académica", str(variables.get('unidad_academica', ''))),
|
| 101 |
-
("Programas que ofrecen el curso", str(variables.get('programas_ofrece', ''))),
|
| 102 |
-
("Vigencia", str(variables.get('vigencia', ''))),
|
| 103 |
-
("Código del curso", str(variables.get('codigo_curso', ''))),
|
| 104 |
-
("Tipo de curso", str(variables.get('tipo_curso', '') if variables.get('tipo_curso', '') != 'Otro' else variables.get('tipo_curso_otro', ''))),
|
| 105 |
-
("Características del curso", ', '.join(map(str, variables.get('caracteristicas_curso', [])))),
|
| 106 |
-
("Modalidad educativa", str(variables.get('modalidad', '') if variables.get('modalidad', '') != 'Otra' else variables.get('modalidad_otra', ''))),
|
| 107 |
-
("Área, núcleo o componente", str(variables.get('nombre_area', ''))),
|
| 108 |
-
("Prerrequisitos", str(variables.get('prerrequisitos', ''))),
|
| 109 |
-
("Correquisitos", str(variables.get('correquisitos', ''))),
|
| 110 |
-
("Créditos académicos", str(variables.get('num_creditos', ''))),
|
| 111 |
-
("Horas de interacción", str(variables.get('horas_interaccion', ''))),
|
| 112 |
-
("Horas de trabajo independiente", str(variables.get('horas_independiente', ''))),
|
| 113 |
-
("Horas totales del curso", str(variables.get('horas_totales', '')))
|
| 114 |
]
|
| 115 |
-
|
| 116 |
for key, value in info_general:
|
| 117 |
row = info_table.add_row().cells
|
| 118 |
-
# Primera celda (clave)
|
| 119 |
row[0].text = key
|
| 120 |
-
|
| 121 |
-
for run in paragraph.runs:
|
| 122 |
-
run.font.bold = True
|
| 123 |
-
run.font.color.rgb = RGBColor(34, 85, 85)
|
| 124 |
-
# Aplicar fondo a la primera celda
|
| 125 |
-
shading_elm_1 = parse_xml(r'<w:shd {} w:fill="D9D9D9"/>'.format(nsdecls('w')))
|
| 126 |
-
row[0]._tc.get_or_add_tcPr().append(shading_elm_1)
|
| 127 |
-
# Segunda celda (valor)
|
| 128 |
row[1].text = value
|
| 129 |
-
|
| 130 |
-
# Secciones con Títulos
|
| 131 |
secciones = [
|
| 132 |
("RELACIONES CON EL PERFIL", str(variables.get('relaciones_perfil', ''))),
|
| 133 |
("INTENCIONALIDADES FORMATIVAS", str(variables.get('intencionalidades', ''))),
|
| 134 |
-
("APORTES DEL CURSO A LA FORMACIÓN INTEGRAL Y A LA FORMACIÓN EN INVESTIGACIÓN", str(variables.get('aportes_formacion', ''))),
|
| 135 |
-
("LÍNEAS DE SENTIDO Y DERROTERO DE PREGUNTAS", f"Líneas de sentido: {str(variables.get('lineas_sentido', ''))}\nDerrotero de preguntas: {str(variables.get('derrotero_preguntas', ''))}"),
|
| 136 |
-
("DESCRIPCIÓN DE LOS CONOCIMIENTOS Y/O SABERES", str(variables.get('descripcion_conocimientos', ''))),
|
| 137 |
-
("METODOLOGÍA", f"Estrategias didácticas: {str(variables.get('estrategias_didacticas', ''))}\nMetodología: {str(variables.get('metodologia', ''))}\nMedios y recursos didácticos: {str(variables.get('medios_recursos', ''))}\nFormas de interacción: {str(variables.get('formas_interaccion', ''))}\nEstrategias de internacionalización: {str(variables.get('estrategias_internacionalizacion', ''))}\nEstrategias de diversidad: {str(variables.get('estrategias_diversidad', ''))}"),
|
| 138 |
-
("EVALUACIÓN", f"Concepción de evaluación: {str(variables.get('concepcion_evaluacion', ''))}\nProcesos de aprendizaje: {str(variables.get('procesos_aprendizaje', ''))}\nMomentos de evaluación y porcentajes: {str(variables.get('momentos_evaluacion', ''))}"),
|
| 139 |
-
("BIBLIOGRAFÍA Y OTRAS FUENTES", str(variables.get('bibliografia', ''))),
|
| 140 |
-
("COMUNIDAD ACADÉMICA QUE PARTICIPÓ EN LA ELABORACIÓN DEL MICROCURRÍCULO", f"Nombres: {str(variables.get('nombres_apellidos', ''))}\nUnidad académica: {str(variables.get('unidad_academica_participantes', ''))}\nFormación académica: {str(variables.get('formacion_academica', ''))}")
|
| 141 |
]
|
| 142 |
-
|
| 143 |
for titulo, contenido in secciones:
|
| 144 |
-
# Añadir título de sección
|
| 145 |
-
parrafo_titulo = doc.add_paragraph(titulo)
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
| 149 |
|
| 150 |
-
# Añadir contenido
|
| 151 |
if '\n' in contenido:
|
| 152 |
for linea in contenido.split('\n'):
|
| 153 |
-
parrafo = doc.add_paragraph(linea)
|
| 154 |
-
parrafo.style = 'List Bullet' # O el estilo que prefieras
|
| 155 |
parrafo.paragraph_format.left_indent = Inches(0.5)
|
| 156 |
else:
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
# Aprobación del Consejo de Unidad Académica
|
| 161 |
-
aprobacion_titulo = doc.add_paragraph("
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
| 165 |
|
| 166 |
aprobacion_parrafo = doc.add_paragraph()
|
| 167 |
aprobacion_parrafo.add_run("Aprobado en Acta número ").bold = False
|
| 168 |
aprobacion_parrafo.add_run("_______________").underline = True
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
# Información del Secretario
|
| 173 |
secretario_info = [
|
| 174 |
-
("
|
| 175 |
-
("
|
| 176 |
-
("Cargo:", "_________________________")
|
| 177 |
]
|
| 178 |
-
|
| 179 |
for label, line in secretario_info:
|
| 180 |
parrafo_label = doc.add_paragraph(label)
|
| 181 |
parrafo_label.runs[0].font.bold = True
|
| 182 |
-
parrafo_label.runs[0].font.color.rgb = RGBColor(34, 85, 85)
|
| 183 |
parrafo_linea = doc.add_paragraph(line)
|
| 184 |
-
parrafo_linea.runs[0].
|
| 185 |
-
|
| 186 |
# Guardar el documento en un objeto de bytes
|
| 187 |
doc_buffer = BytesIO()
|
| 188 |
doc.save(doc_buffer)
|
| 189 |
doc_buffer.seek(0)
|
| 190 |
-
|
| 191 |
return doc_buffer
|
| 192 |
|
| 193 |
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
+
from io import BytesIO
|
| 75 |
+
from docx import Document
|
| 76 |
+
from docx.shared import Pt, Inches, RGBColor
|
| 77 |
+
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
| 78 |
+
|
| 79 |
def crear_documento(nombre_curso, variables):
|
| 80 |
+
doc = Document('plantilla_temporal.docx')
|
| 81 |
+
|
| 82 |
+
# Insertar la imagen con estilo centrado
|
| 83 |
+
imagen = doc.add_paragraph()
|
| 84 |
+
imagen.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
| 85 |
+
run_imagen = imagen.add_run()
|
| 86 |
+
run_imagen.add_picture("UdeA+simplificado-01.png", width=Inches(1.5))
|
| 87 |
|
| 88 |
# Título Principal
|
| 89 |
titulo = doc.add_paragraph()
|
|
|
|
| 90 |
titulo_run = titulo.add_run("PROGRAMA OFICIAL DE CURSO\n(Pregrado y Posgrado)\nUNIVERSIDAD DE ANTIOQUIA")
|
| 91 |
titulo_run.bold = True
|
| 92 |
titulo_run.font.size = Pt(16)
|
| 93 |
+
titulo_run.font.color.rgb = RGBColor(34, 85, 85) # Color verde azulado
|
| 94 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Información General - Tabla
|
| 96 |
+
doc.add_paragraph("\nINFORMACIÓN GENERAL", style='Heading 1')
|
| 97 |
info_table = doc.add_table(rows=0, cols=2)
|
| 98 |
+
info_table.style = 'Table Grid'
|
| 99 |
+
|
| 100 |
info_general = [
|
| 101 |
("Nombre del curso", nombre_curso),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
]
|
| 103 |
+
|
| 104 |
for key, value in info_general:
|
| 105 |
row = info_table.add_row().cells
|
|
|
|
| 106 |
row[0].text = key
|
| 107 |
+
row[0].paragraphs[0].runs[0].font.bold = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
row[1].text = value
|
| 109 |
+
|
| 110 |
+
# Secciones con Títulos
|
| 111 |
secciones = [
|
| 112 |
("RELACIONES CON EL PERFIL", str(variables.get('relaciones_perfil', ''))),
|
| 113 |
("INTENCIONALIDADES FORMATIVAS", str(variables.get('intencionalidades', ''))),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
]
|
| 115 |
+
|
| 116 |
for titulo, contenido in secciones:
|
| 117 |
+
# Añadir título de sección con color personalizado
|
| 118 |
+
parrafo_titulo = doc.add_paragraph(f"\n{titulo}")
|
| 119 |
+
run_titulo = parrafo_titulo.runs[0]
|
| 120 |
+
run_titulo.font.size = Pt(14)
|
| 121 |
+
run_titulo.bold = True
|
| 122 |
+
run_titulo.font.color.rgb = RGBColor(34, 85, 85) # Color verde azulado
|
| 123 |
|
| 124 |
+
# Añadir contenido con viñetas si es necesario
|
| 125 |
if '\n' in contenido:
|
| 126 |
for linea in contenido.split('\n'):
|
| 127 |
+
parrafo = doc.add_paragraph(linea, style='List Bullet')
|
|
|
|
| 128 |
parrafo.paragraph_format.left_indent = Inches(0.5)
|
| 129 |
else:
|
| 130 |
+
doc.add_paragraph(contenido)
|
| 131 |
+
|
|
|
|
| 132 |
# Aprobación del Consejo de Unidad Académica
|
| 133 |
+
aprobacion_titulo = doc.add_paragraph("\nAPROBACIÓN DEL CONSEJO DE UNIDAD ACADÉMICA")
|
| 134 |
+
aprobacion_titulo_run = aprobacion_titulo.runs[0]
|
| 135 |
+
aprobacion_titulo_run.bold = True
|
| 136 |
+
aprobacion_titulo_run.font.size = Pt(14)
|
| 137 |
+
aprobacion_titulo_run.font.color.rgb = RGBColor(34, 85, 85) # Color verde azulado
|
| 138 |
|
| 139 |
aprobacion_parrafo = doc.add_paragraph()
|
| 140 |
aprobacion_parrafo.add_run("Aprobado en Acta número ").bold = False
|
| 141 |
aprobacion_parrafo.add_run("_______________").underline = True
|
| 142 |
+
|
| 143 |
+
# Información del secretario (puedes ajustar según tus necesidades)
|
|
|
|
|
|
|
| 144 |
secretario_info = [
|
| 145 |
+
("Secretario Académico", "________________________"),
|
| 146 |
+
("Decano", "________________________"),
|
|
|
|
| 147 |
]
|
| 148 |
+
|
| 149 |
for label, line in secretario_info:
|
| 150 |
parrafo_label = doc.add_paragraph(label)
|
| 151 |
parrafo_label.runs[0].font.bold = True
|
| 152 |
+
parrafo_label.runs[0].font.color.rgb = RGBColor(34, 85, 85) # Color verde azulado
|
| 153 |
parrafo_linea = doc.add_paragraph(line)
|
| 154 |
+
parrafo_linea.runs[0].underline = True
|
| 155 |
+
|
| 156 |
# Guardar el documento en un objeto de bytes
|
| 157 |
doc_buffer = BytesIO()
|
| 158 |
doc.save(doc_buffer)
|
| 159 |
doc_buffer.seek(0)
|
|
|
|
| 160 |
return doc_buffer
|
| 161 |
|
| 162 |
|