Update app.py
Browse files
app.py
CHANGED
|
@@ -47,6 +47,7 @@ import Azure_api
|
|
| 47 |
from flask import Flask, render_template, session, redirect, url_for
|
| 48 |
from flask_session import Session # Capital "S"
|
| 49 |
import os, traceback
|
|
|
|
| 50 |
|
| 51 |
######################################################### FLASK APP #################################################################################################################################
|
| 52 |
app = Flask(__name__)
|
|
@@ -1087,6 +1088,8 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0,pdf_content=0,csvfile=0):
|
|
| 1087 |
SearchArray=result[7]
|
| 1088 |
print('searchhh:',SearchArray)
|
| 1089 |
print('csv',csvfile)
|
|
|
|
|
|
|
| 1090 |
# annotatedimg,pdf_document,spreadsheet_url, list1 , df_doors=doors_fasterrcnn.main_run(img,dataDoc,'separated_classes_all.pth',result[0],pdfpath, result[4]) #single_double.pth
|
| 1091 |
if pdf_content:
|
| 1092 |
link = urllib.parse.unquote(result[6].strip('"'))
|
|
@@ -1102,14 +1105,49 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0,pdf_content=0,csvfile=0):
|
|
| 1102 |
# pdf_contentSched = fitz.open(stream=pdf_contentSched, filetype="pdf")
|
| 1103 |
annotatedimgs, pdf_document , list1, repeated_labels , not_found, bax_pretty_xml, column_xml =Doors_Schedule.mainRun(pdf_contentSched, dataDoc, SearchArray,pdf_content,pdf_contentSched)
|
| 1104 |
else:
|
| 1105 |
-
|
| 1106 |
-
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
| 1110 |
-
|
| 1111 |
-
|
| 1112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1113 |
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 1114 |
pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname="combined_output.pdf") #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
|
| 1115 |
|
|
|
|
| 47 |
from flask import Flask, render_template, session, redirect, url_for
|
| 48 |
from flask_session import Session # Capital "S"
|
| 49 |
import os, traceback
|
| 50 |
+
from werkzeug.utils import secure_filename
|
| 51 |
|
| 52 |
######################################################### FLASK APP #################################################################################################################################
|
| 53 |
app = Flask(__name__)
|
|
|
|
| 1088 |
SearchArray=result[7]
|
| 1089 |
print('searchhh:',SearchArray)
|
| 1090 |
print('csv',csvfile)
|
| 1091 |
+
CSV_UPLOAD_DIR = os.path.join(os.path.dirname(__file__), "uploaded_csv")
|
| 1092 |
+
|
| 1093 |
# annotatedimg,pdf_document,spreadsheet_url, list1 , df_doors=doors_fasterrcnn.main_run(img,dataDoc,'separated_classes_all.pth',result[0],pdfpath, result[4]) #single_double.pth
|
| 1094 |
if pdf_content:
|
| 1095 |
link = urllib.parse.unquote(result[6].strip('"'))
|
|
|
|
| 1105 |
# pdf_contentSched = fitz.open(stream=pdf_contentSched, filetype="pdf")
|
| 1106 |
annotatedimgs, pdf_document , list1, repeated_labels , not_found, bax_pretty_xml, column_xml =Doors_Schedule.mainRun(pdf_contentSched, dataDoc, SearchArray,pdf_content,pdf_contentSched)
|
| 1107 |
else:
|
| 1108 |
+
sch_csv_pdf = False
|
| 1109 |
+
file_names = result[6] # ["7376....csv", "something.csv"] in CSV mode or PDF names in PDF mode
|
| 1110 |
+
if not file_names:
|
| 1111 |
+
raise ValueError("No schedule files provided in result[6].")
|
| 1112 |
+
|
| 1113 |
+
first_name = str(file_names[0]).lower()
|
| 1114 |
+
|
| 1115 |
+
if first_name.endswith(".csv"):
|
| 1116 |
+
# 🔹 CSV MODE
|
| 1117 |
+
|
| 1118 |
+
# Ensure folder exists
|
| 1119 |
+
os.makedirs(CSV_UPLOAD_DIR, exist_ok=True)
|
| 1120 |
+
|
| 1121 |
+
# Grab uploaded CSV files from the request
|
| 1122 |
+
# name="csvFilename" from your <input type="file">
|
| 1123 |
+
uploaded_csvs = request.files.getlist("csvFilename")
|
| 1124 |
+
|
| 1125 |
+
saved_paths = []
|
| 1126 |
+
|
| 1127 |
+
for f in uploaded_csvs:
|
| 1128 |
+
if not f.filename:
|
| 1129 |
+
continue
|
| 1130 |
+
safe_name = secure_filename(f.filename)
|
| 1131 |
+
save_path = os.path.join(CSV_UPLOAD_DIR, safe_name)
|
| 1132 |
+
f.save(save_path)
|
| 1133 |
+
saved_paths.append(save_path)
|
| 1134 |
+
|
| 1135 |
+
annotatedimgs, pdf_document, list1, repeated_labels, not_found, bax_pretty_xml, column_xml = Doors_Schedule.mainRun(
|
| 1136 |
+
saved_paths, # 👉 ["file1.csv", "file2.csv"]
|
| 1137 |
+
dataDoc,
|
| 1138 |
+
SearchArray,
|
| 1139 |
+
sch_csv_pdf
|
| 1140 |
+
)
|
| 1141 |
+
else:
|
| 1142 |
+
dataDocDoorsSchedule = []
|
| 1143 |
+
sch_csv_pdf = True
|
| 1144 |
+
for r in result[6]:
|
| 1145 |
+
pdfpathDoors,_=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= r)
|
| 1146 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 1147 |
+
md, resDoors =dbxTeam.files_download(path=pdfpathDoors)
|
| 1148 |
+
dataDocDoorsSchedule.append(resDoors.content)
|
| 1149 |
+
annotatedimgs, pdf_document , list1, repeated_labels , not_found, bax_pretty_xml, column_xml =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc, SearchArray, sch_csv_pdf)
|
| 1150 |
+
|
| 1151 |
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 1152 |
pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname="combined_output.pdf") #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
|
| 1153 |
|