File size: 3,530 Bytes
97d7a98
1e2d425
e72ad57
f34bcc8
6fa8043
4e3ae73
02af7c0
 
1e2d425
766f2b6
d19d78e
 
f5d33ec
 
 
 
 
 
d19d78e
 
 
02af7c0
f5d33ec
 
 
 
 
 
 
 
02af7c0
 
 
f5d33ec
 
 
 
 
 
 
 
 
02af7c0
 
 
1d56743
 
d19d78e
 
 
 
 
 
 
 
 
 
02af7c0
f5d33ec
 
 
1d56743
 
621aee6
 
 
 
 
 
 
 
1d56743
 
 
016939b
 
1d56743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621aee6
 
 
 
 
f5d33ec
1e2d425
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from flask import Flask, request, jsonify, abort , render_template ,  send_file
import tsadropboxretrieval
import json
import Find_Hyperlinking_text
import requests
from io import BytesIO
import urllib

app = Flask(__name__)

pdf_content = None
pageNumTextFound = 0
BASE_URL = "https://marthee-nbslink.hf.space"  # Hugging Face Spaces base URL

@app.route("/", methods=["GET", "POST"])
def thismain():
    print('ayhaga')
    return render_template("gui.html")

@app.route('/view-pdf', methods=['GET'])
def download_pdf():

    # Manually parse the query parameters
    full_query_string = request.query_string.decode()  # Get raw query string
    parsed_params = urllib.parse.parse_qs(full_query_string)  # Parse it

    # Extract pdfLink and keyword manually
    pdf_link = parsed_params.get('pdfLink', [None])[0]
    keyword = parsed_params.get('keyword', [None])[0]

    if not pdf_link or not keyword:
        return "Missing required parameters.", 400

    # Decode the extracted values
    pdf_link = urllib.parse.unquote(pdf_link)
    keyword = urllib.parse.unquote(keyword)

    # If the keyword is a JSON string, convert it back to a list
    try:
        keyword = json.loads(keyword)
    except json.JSONDecodeError:
        keyword = [keyword]  # Treat it as a single keyword if not JSON

    print("Extracted PDF Link:", pdf_link)
    print("Extracted Keywords:", keyword)
    createDF=False
    outputDone = Find_Hyperlinking_text.annotate_text_from_pdf([pdf_link], keyword)
    if pdf_content is None:
        return "PDF content not found.", 404

    pdf_bytes = BytesIO(pdf_content)
    return send_file(
        pdf_bytes,
        mimetype='application/pdf',
        as_attachment=False,
        download_name=f"annotated_page_{pageNumTextFound}.pdf"
    )
def finddata():
    pdfLink = 'https://www.dropbox.com/scl/fi/hnp4mqigb51a5kp89kgfa/00801-ARC-20-ZZ-S-A-0002.pdf?rlkey=45abeoebzqw4qwnslnei6dkd6&st=m4yrcjm2&dl=1'
    keyword = ['115 INTEGRATED MRI ROOM LININGS', '710 TRANSPORTATION']
    return pdfLink, keyword

    
@app.route('/apiNBSData', methods=['POST'])
def NBSData():


    try:
        print('In process [Try]')
        data = request.get_json()
        # Extracting values
        pdfLink = data.get('filePath')
        keyword = data.get('NBS_List')

        if not pdfLink or not keyword:
            return jsonify({"error": "Both 'pdfLink' and 'keyword' must be provided."}), 400

        print(pdfLink, keyword)
  
        pdf_document ,tablepdf= Find_Hyperlinking_text.annotate_text_from_pdf([pdfLink], keyword)
        dbxTeam= tsadropboxretrieval.ADR_Access_DropboxTeam('user')

        # Get metadata using the shared link
        metadata = dbxTeam.sharing_get_shared_link_metadata(pdfLink)
        dbPath='/TSA JOBS/ADR Test/FIND/'
        pdflink= tsadropboxretrieval.uploadanyFile(doc=pdf_document,path=dbPath,pdfname=metadata.name) #doc=doc,pdfname=path,pdfpath=pdfpath+'Measured Plan/
        print('LINKS0',pdflink)
        dbPath='/TSA JOBS/ADR Test/FIND/'
        tablepdfLink=tsadropboxretrieval.uploadanyFile(doc=tablepdf,path=dbPath,pdfname=metadata.name+' Markup Summary')
        print(f"PDF successfully uploaded to Dropbox at")
        print('LINKS1',tablepdfLink)
        return jsonify({
            "message": "PDF processed successfully.",
            "download_link": 'done'
        })

    
    except Exception as e:
        print(f"Error: {e}")
        return jsonify({"error": str(e)}), 500

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)