Marthee commited on
Commit
68803d0
·
verified ·
1 Parent(s): 6acab05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -30
app.py CHANGED
@@ -9,46 +9,28 @@ def getInfotoMeasure():
9
  return render_template("gui.html")
10
  # Route to serve the PDF in iframe
11
 
12
- @app.route('/view-pdf')
13
- def view_pdf():
 
14
  link = 'https://www.dropbox.com/scl/fi/fjykwhhn9gu9t3kqrflxd/LA002-NOR-ZZ-ZZ-T-A-2403_Architectural-Specification-F10-Brick-and-Block-Walling_A4-_C01.pdf?rlkey=ek9i66i79m0hwp8z5yjs6rp5p&st=jh05a6qs&dl=0'
15
 
 
16
  if 'dl=0' in link:
17
  link = link.replace('dl=0', 'dl=1')
18
 
 
19
  response = requests.get(link)
 
20
 
21
- if response.status_code == 200:
22
- pdf_path = 'temp_view.pdf'
23
- with open(pdf_path, 'wb') as f:
24
- f.write(response.content)
25
-
26
- # Serve PDF with CSP header
27
- response = send_file(pdf_path, mimetype='application/pdf')
28
- response.headers['Content-Security-Policy'] = "frame-src *;"
29
- return response
30
- else:
31
- return "Failed to download PDF content", 404
32
 
33
  if __name__ == '__main__':
34
  app.run(host='0.0.0.0', port=7860)
35
- # from flask import Flask, request, jsonify
36
-
37
- # app = Flask(__name__)
38
-
39
- # @app.route('/api/process-data', methods=['POST'])
40
- # def process_data():
41
- # # Get JSON data from the request
42
- # data = request.get_json()
43
-
44
- # # Perform some processing on the data
45
- # # For example, let's just return the data back with a message
46
- # processed_data = {
47
- # 'message': 'Data received and processed successfully!',
48
- # 'received_data': data
49
- # }
50
-
51
- # return jsonify(processed_data)
52
 
53
  # if __name__ == '__main__':
54
  # app.run(host='0.0.0.0', port=7860, debug=True)
 
9
  return render_template("gui.html")
10
  # Route to serve the PDF in iframe
11
 
12
+ @app.route('/pdf', methods=['GET'])
13
+ def serve_pdf():
14
+ # Dropbox link
15
  link = 'https://www.dropbox.com/scl/fi/fjykwhhn9gu9t3kqrflxd/LA002-NOR-ZZ-ZZ-T-A-2403_Architectural-Specification-F10-Brick-and-Block-Walling_A4-_C01.pdf?rlkey=ek9i66i79m0hwp8z5yjs6rp5p&st=jh05a6qs&dl=0'
16
 
17
+ # Convert Dropbox link for direct download
18
  if 'dl=0' in link:
19
  link = link.replace('dl=0', 'dl=1')
20
 
21
+ # Download the PDF content
22
  response = requests.get(link)
23
+ pdf_content = BytesIO(response.content)
24
 
25
+ # Serve the PDF
26
+ return send_file(
27
+ pdf_content,
28
+ download_name="document.pdf", # Name the file
29
+ mimetype="application/pdf"
30
+ )
 
 
 
 
 
31
 
32
  if __name__ == '__main__':
33
  app.run(host='0.0.0.0', port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # if __name__ == '__main__':
36
  # app.run(host='0.0.0.0', port=7860, debug=True)