34 lines
961 B
Python
34 lines
961 B
Python
import streamlit as st
|
|
import os
|
|
|
|
# @st.cache_data
|
|
|
|
|
|
def import_file() -> str:
|
|
# Cargar el archivo pdf
|
|
archivo = st.file_uploader(
|
|
'Arrastra o ingresa tu archivo .pdf', type=['.pdf'])
|
|
nombre_archivo: str = ''
|
|
# Verificar si se ha cargado un archivo
|
|
if archivo is not None:
|
|
|
|
nombre_archivo = archivo.name
|
|
# Abrir un archivo en modo escritura binaria ('wb') para guardar el archivo de audio
|
|
|
|
with open(f'documents/pdfs/{nombre_archivo}', 'wb') as new_file:
|
|
# Leer los datos del archivo cargado y escribirlos en el nuevo archivo
|
|
new_file.write(archivo.read())
|
|
|
|
return nombre_archivo
|
|
|
|
# Define la función para borrar el caché
|
|
|
|
|
|
def clear_cache():
|
|
cache_path = os.path.join(st.__path__[0], 'static', 'cache')
|
|
for root, dirs, files in os.walk(cache_path):
|
|
for file in files:
|
|
os.remove(os.path.join(root, file))
|
|
st.success('Cache limpio exitosamente.')
|
|
|