Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,27 +8,51 @@ app = Flask(__name__)
|
|
| 8 |
def getInfotoMeasure():
|
| 9 |
return render_template("gui.html")
|
| 10 |
# Route to serve the PDF in iframe
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 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(
|
|
|
|
|
|
|
|
|
|
| 23 |
pdf_content = BytesIO(response.content)
|
| 24 |
-
|
| 25 |
# Serve the PDF
|
| 26 |
return send_file(
|
| 27 |
pdf_content,
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
if __name__ == '__main__':
|
| 33 |
app.run(host='0.0.0.0', port=7860)
|
| 34 |
|
|
|
|
| 8 |
def getInfotoMeasure():
|
| 9 |
return render_template("gui.html")
|
| 10 |
# Route to serve the PDF in iframe
|
| 11 |
+
from flask import Flask, send_file, render_template
|
| 12 |
+
import requests
|
| 13 |
+
from io import BytesIO
|
| 14 |
|
| 15 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
@app.route('/download-pdf', methods=['GET'])
|
| 18 |
+
def download_pdf():
|
| 19 |
+
"""
|
| 20 |
+
Download the PDF from Dropbox and serve it for iframe embedding.
|
| 21 |
+
"""
|
| 22 |
+
dropbox_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'
|
| 23 |
+
|
| 24 |
+
# Modify Dropbox link to enable direct download
|
| 25 |
+
if 'dl=0' in dropbox_link:
|
| 26 |
+
dropbox_link = dropbox_link.replace('dl=0', 'dl=1')
|
| 27 |
+
|
| 28 |
# Download the PDF content
|
| 29 |
+
response = requests.get(dropbox_link)
|
| 30 |
+
if response.status_code != 200:
|
| 31 |
+
return "Failed to download the PDF.", 500
|
| 32 |
+
|
| 33 |
pdf_content = BytesIO(response.content)
|
| 34 |
+
|
| 35 |
# Serve the PDF
|
| 36 |
return send_file(
|
| 37 |
pdf_content,
|
| 38 |
+
mimetype='application/pdf',
|
| 39 |
+
as_attachment=False,
|
| 40 |
+
download_name="downloaded_document.pdf"
|
| 41 |
)
|
| 42 |
|
| 43 |
+
@app.route('/view-pdf', methods=['GET'])
|
| 44 |
+
def view_pdf():
|
| 45 |
+
"""
|
| 46 |
+
Render an HTML page with the iframe to display the PDF.
|
| 47 |
+
"""
|
| 48 |
+
return render_template('gui.html') # Ensure this file exists in the 'templates' folder
|
| 49 |
+
|
| 50 |
+
@app.route('/', methods=['GET'])
|
| 51 |
+
def view_pdf0():
|
| 52 |
+
|
| 53 |
+
return render_template('gui.html') # Ensure this file exists in the 'templates' folder
|
| 54 |
+
|
| 55 |
+
|
| 56 |
if __name__ == '__main__':
|
| 57 |
app.run(host='0.0.0.0', port=7860)
|
| 58 |
|