From e211397d866ff7955808e2d3175f784d762c0253 Mon Sep 17 00:00:00 2001 From: zer0 Date: Sat, 4 May 2024 23:36:20 -0500 Subject: [PATCH] Refactor file handling and add database configuration in backend/app.py --- backend/{main.py => app.py} | 4 ++++ frontend/pages/rode.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) rename backend/{main.py => app.py} (79%) diff --git a/backend/main.py b/backend/app.py similarity index 79% rename from backend/main.py rename to backend/app.py index 4b1170c..c902f14 100644 --- a/backend/main.py +++ b/backend/app.py @@ -1,6 +1,7 @@ from flask import Flask from flask_restful import Api import sentry_sdk +import os from resources import ( TilDeV1, @@ -15,7 +16,10 @@ profiles_sample_rate=1.0, ) +basedir = os.path.abspath(os.path.dirname(__file__)) + app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] ='sqlite:///' + os.path.join(basedir, 'database.db') api = Api(app) api.add_resource(TilDeV1, "/tilde/v1") diff --git a/frontend/pages/rode.py b/frontend/pages/rode.py index cf6ddfb..6e65290 100644 --- a/frontend/pages/rode.py +++ b/frontend/pages/rode.py @@ -35,6 +35,8 @@ alerts = st.empty() +fin_process = st.empty() + dataframe = pd.DataFrame(columns=["archivo", "predicción", "confianza", "tiempo(s)"]) bad_dataframe = pd.DataFrame(columns=["archivo", "predicción", "confianza", "tiempo(s)"]) @@ -54,7 +56,7 @@ def process_uploaded_images(uploaded_file, show_image, version="v1"): for file in uploaded_file: image = file.read() - response = ImageProccesing("rode").process_file(image, version) + response = ImageProccesing("rode").process_file(image, version, file.name) filtered = hoja_control(image) # cambiar nombres a español @@ -116,7 +118,7 @@ def process_pdf_file(uploaded_pdf, show_image, version="v1"): filtered = hoja_control(image) with open(image_path, "rb") as image: - response = ImageProccesing("rode").process_file(image, version) + response = ImageProccesing("rode").process_file(image, version, pdf.name, i + 1, "pdf") #change names to spanish response['data'][0]['name'] = "rotado" if response['data'][0]['name'] == "rotated" else "no rotado" @@ -164,8 +166,10 @@ def process_pdf_file(uploaded_pdf, show_image, version="v1"): def main(): if uploaded_file: process_uploaded_images(uploaded_file, show_image, version) + fin_process.info(f'Fin del procesamiento: **{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}**') if uploaded_pdf: process_pdf_file(uploaded_pdf, show_image, version) + fin_process.info(f'Fin del procesamiento: **{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}**') if __name__ == "__main__": main() \ No newline at end of file