Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,37 @@
|
|
| 1 |
-
from flask import Flask,
|
| 2 |
import requests
|
| 3 |
from io import BytesIO
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
app = Flask(__name__)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
@app.route("/", methods=["GET", "POST"])
|
| 22 |
-
def
|
| 23 |
-
"""
|
| 24 |
-
Render the main GUI with the iframe.
|
| 25 |
-
"""
|
| 26 |
return render_template("gui.html")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
# Route to serve the PDF in iframe
|
| 38 |
-
@app.route('/download-pdf', methods=['GET'])
|
| 39 |
-
def serve_pdf():
|
| 40 |
-
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'
|
| 41 |
-
if 'dl=0' in link:
|
| 42 |
-
link = link.replace('dl=0', 'dl=1')
|
| 43 |
-
response = requests.get(link)
|
| 44 |
pdf_content = BytesIO(response.content)
|
| 45 |
-
return send_file(pdf_content, download_name="document.pdf", mimetype="application/pdf")
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
if __name__ == '__main__':
|
| 62 |
-
|
| 63 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, send_file
|
| 2 |
import requests
|
| 3 |
from io import BytesIO
|
| 4 |
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
|
| 7 |
+
# Main route to render HTML template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
@app.route("/", methods=["GET", "POST"])
|
| 9 |
+
def getInfotoMeasure():
|
|
|
|
|
|
|
|
|
|
| 10 |
return render_template("gui.html")
|
| 11 |
|
| 12 |
+
# Route to serve PDF with a specified page
|
| 13 |
+
@app.route('/view-pdf', methods=['GET'])
|
| 14 |
+
def download_pdf():
|
| 15 |
+
page = request.args.get('page', default=1) # Get page number from query parameter
|
| 16 |
+
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'
|
| 17 |
|
| 18 |
+
# Modify Dropbox link to enable direct download
|
| 19 |
+
if 'dl=0' in dropbox_link:
|
| 20 |
+
dropbox_link = dropbox_link.replace('dl=0', 'dl=1')
|
| 21 |
|
| 22 |
+
response = requests.get(dropbox_link)
|
| 23 |
|
| 24 |
+
if response.status_code != 200:
|
| 25 |
+
return "Failed to download the PDF.", 500
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
pdf_content = BytesIO(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
return send_file(
|
| 30 |
+
pdf_content,
|
| 31 |
+
mimetype='application/pdf',
|
| 32 |
+
as_attachment=False,
|
| 33 |
+
download_name=f"document_page_{page}.pdf"
|
| 34 |
+
)
|
| 35 |
|
| 36 |
if __name__ == '__main__':
|
| 37 |
+
app.run(host='0.0.0.0', port=7860)
|
|
|