Skip to content

Commit

Permalink
Refactor file handling and add database configuration in backend/app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik172 committed May 5, 2024
1 parent 52d7bd0 commit e211397
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backend/main.py → backend/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Flask
from flask_restful import Api
import sentry_sdk
import os

from resources import (
TilDeV1,
Expand All @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions frontend/pages/rode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"])

Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()

0 comments on commit e211397

Please sign in to comment.