Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,6 +40,7 @@ import Code_2_7
|
|
| 40 |
import Counting_Columns_2_1
|
| 41 |
# import Find_Hyperlinking_text
|
| 42 |
import ezdxf
|
|
|
|
| 43 |
from flask import Flask, render_template, session, redirect, url_for
|
| 44 |
from flask_session import Session # Capital "S"
|
| 45 |
app = Flask(__name__)
|
|
@@ -160,6 +161,10 @@ def get_javascript_data(jsdata):
|
|
| 160 |
def searchDocument():
|
| 161 |
return render_template('wordSearch.html')
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
@app.route('/legends',methods=["GET", "POST"])
|
| 164 |
def legendDirectory():
|
| 165 |
return render_template('legendDirectory.html')
|
|
@@ -234,7 +239,31 @@ def getfromdropboxImg(jsdata):
|
|
| 234 |
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 235 |
_, buffer = cv2.imencode('.png', img)
|
| 236 |
return base64.b64encode(buffer).decode('utf-8')
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
@app.route('/savebase64Img/',methods=["POST"])
|
| 240 |
def stringToRGB():
|
|
@@ -266,17 +295,35 @@ def stringToRGB():
|
|
| 266 |
|
| 267 |
|
| 268 |
if vv[5][2].startswith('2.8') or vv[5][2].startswith('2.6') or vv[5][2].startswith('2.1'):
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
return jsonify(arr)
|
| 281 |
|
| 282 |
@app.route('/2.1Trial/',methods=["POST"])
|
|
@@ -385,7 +432,7 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0):
|
|
| 385 |
# 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
|
| 386 |
annotatedimg, pdf_document , list1, repeated_labels , not_found =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc, SearchArray)
|
| 387 |
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 388 |
-
pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname=
|
| 389 |
_, buffer = cv2.imencode('.png', annotatedimg)
|
| 390 |
repeatedLabelsReturn=''
|
| 391 |
NotFoundReturn=''
|
|
@@ -787,7 +834,7 @@ def receive_pdf_data():
|
|
| 787 |
|
| 788 |
pdfbytes, pdf_document , df ,tablepdfoutput= Find_Hyperlinking_text.annotate_text_from_pdf([pdfLink], keyword)
|
| 789 |
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 790 |
-
|
| 791 |
# Get metadata using the shared link
|
| 792 |
metadata = dbxTeam.sharing_get_shared_link_metadata(pdfLink)
|
| 793 |
dbPath='/TSA JOBS/ADR Test/FIND/'
|
|
|
|
| 40 |
import Counting_Columns_2_1
|
| 41 |
# import Find_Hyperlinking_text
|
| 42 |
import ezdxf
|
| 43 |
+
import Azure_api
|
| 44 |
from flask import Flask, render_template, session, redirect, url_for
|
| 45 |
from flask_session import Session # Capital "S"
|
| 46 |
app = Flask(__name__)
|
|
|
|
| 161 |
def searchDocument():
|
| 162 |
return render_template('wordSearch.html')
|
| 163 |
|
| 164 |
+
@app.route('/tableDetection',methods=["GET", "POST"])
|
| 165 |
+
def TableDetection():
|
| 166 |
+
return render_template('tableDetection.html')
|
| 167 |
+
|
| 168 |
@app.route('/legends',methods=["GET", "POST"])
|
| 169 |
def legendDirectory():
|
| 170 |
return render_template('legendDirectory.html')
|
|
|
|
| 239 |
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
| 240 |
_, buffer = cv2.imencode('.png', img)
|
| 241 |
return base64.b64encode(buffer).decode('utf-8')
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
@app.route('/savedetectedtables/',methods=["POST"])
|
| 245 |
+
def table():
|
| 246 |
+
# 1. Get PDF bytes from Dropbox
|
| 247 |
+
tt = eval(request.form.get('answers')) # consider json.loads instead of eval
|
| 248 |
+
pdfpath, _ = tsadropboxretrieval.getPathtoPDF_File(nameofPDF=tt[0])
|
| 249 |
+
dbx = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 250 |
+
_, res = dbx.files_download(path=pdfpath)
|
| 251 |
+
pdf_bytes = res.content
|
| 252 |
+
|
| 253 |
+
# 2. Generate in-memory Excel
|
| 254 |
+
excel_io = Azure_api.detect_tables(pdf_bytes)
|
| 255 |
+
print('type(excel_io) = ', type(excel_io))
|
| 256 |
+
# 3. Send it as a downloadable .xlsx
|
| 257 |
+
if excel_io is None:
|
| 258 |
+
# No tables → return a JSON error (or another response of your choice)
|
| 259 |
+
return ('', 204)
|
| 260 |
+
|
| 261 |
+
return send_file(
|
| 262 |
+
excel_io,
|
| 263 |
+
as_attachment=True,
|
| 264 |
+
download_name='detected_tables.xlsx',
|
| 265 |
+
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
| 266 |
+
)
|
| 267 |
|
| 268 |
@app.route('/savebase64Img/',methods=["POST"])
|
| 269 |
def stringToRGB():
|
|
|
|
| 295 |
|
| 296 |
|
| 297 |
if vv[5][2].startswith('2.8') or vv[5][2].startswith('2.6') or vv[5][2].startswith('2.1'):
|
| 298 |
+
print(f"el mawgood fe vv[0]: {vv[0]}")
|
| 299 |
+
arr_s = []
|
| 300 |
+
dataDocs = []
|
| 301 |
+
pls = []
|
| 302 |
+
for v in vv[0]:
|
| 303 |
+
pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(v))
|
| 304 |
+
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 305 |
+
md, res =dbxTeam.files_download(path=pdfpath)
|
| 306 |
+
dataDoc = res.content
|
| 307 |
+
dataDocs.append(dataDoc)
|
| 308 |
+
doc = fitz.open("pdf",dataDoc)
|
| 309 |
+
page=doc[0]
|
| 310 |
+
if page.rotation!=0:
|
| 311 |
+
page.set_rotation(0)
|
| 312 |
+
pix = page.get_pixmap(dpi=300) # render page to an image
|
| 313 |
+
pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
|
| 314 |
+
pls.append(pl)
|
| 315 |
+
arr=measureproject(vv,dataDocs,pls)
|
| 316 |
+
#pdfpath,pdflink=tsadropboxretrieval.getPathtoPDF_File(nameofPDF= str(vv[0]))
|
| 317 |
+
#dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 318 |
+
#md, res =dbxTeam.files_download(path=pdfpath)
|
| 319 |
+
#dataDoc = res.content
|
| 320 |
+
#doc = fitz.open("pdf",dataDoc)
|
| 321 |
+
#page=doc[0]
|
| 322 |
+
#if page.rotation!=0:
|
| 323 |
+
# page.set_rotation(0)
|
| 324 |
+
#pix = page.get_pixmap(dpi=300) # render page to an image
|
| 325 |
+
#pl=Image.frombytes('RGB', [pix.width,pix.height],pix.samples)
|
| 326 |
+
#arr=measureproject(vv,dataDoc,pl)
|
| 327 |
return jsonify(arr)
|
| 328 |
|
| 329 |
@app.route('/2.1Trial/',methods=["POST"])
|
|
|
|
| 432 |
# 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
|
| 433 |
annotatedimg, pdf_document , list1, repeated_labels , not_found =Doors_Schedule.mainRun(dataDocDoorsSchedule, dataDoc, SearchArray)
|
| 434 |
dbPath='/TSA JOBS/ADR Test'+pdfpath+'Measured Plan/'
|
| 435 |
+
pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname="combined_output.pdf") #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
|
| 436 |
_, buffer = cv2.imencode('.png', annotatedimg)
|
| 437 |
repeatedLabelsReturn=''
|
| 438 |
NotFoundReturn=''
|
|
|
|
| 834 |
|
| 835 |
pdfbytes, pdf_document , df ,tablepdfoutput= Find_Hyperlinking_text.annotate_text_from_pdf([pdfLink], keyword)
|
| 836 |
dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 837 |
+
|
| 838 |
# Get metadata using the shared link
|
| 839 |
metadata = dbxTeam.sharing_get_shared_link_metadata(pdfLink)
|
| 840 |
dbPath='/TSA JOBS/ADR Test/FIND/'
|