Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,32 @@
|
|
| 1 |
-
from flask import Flask, send_file,
|
| 2 |
import requests
|
| 3 |
from io import BytesIO
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
app = Flask(__name__)
|
| 7 |
|
| 8 |
-
# Route to serve the PDF
|
| 9 |
@app.route('/view-pdf')
|
| 10 |
def view_pdf():
|
| 11 |
-
# Dropbox link
|
| 12 |
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'
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
if 'dl=0' in link:
|
| 16 |
link = link.replace('dl=0', 'dl=1')
|
| 17 |
|
| 18 |
-
# Download PDF
|
| 19 |
response = requests.get(link)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
#
|
| 31 |
-
@app.route('/pdf-viewer')
|
| 32 |
-
def pdf_viewer():
|
| 33 |
-
# Embed the iframe to navigate to page 2
|
| 34 |
-
html_content = '''
|
| 35 |
-
<!DOCTYPE html>
|
| 36 |
-
<html lang="en">
|
| 37 |
-
<head>
|
| 38 |
-
<meta charset="UTF-8">
|
| 39 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 40 |
-
<title>PDF Viewer</title>
|
| 41 |
-
</head>
|
| 42 |
-
<body>
|
| 43 |
-
<h1>PDF Viewer</h1>
|
| 44 |
-
<iframe
|
| 45 |
-
src="/view-pdf#page=2"
|
| 46 |
-
width="100%"
|
| 47 |
-
height="800px"
|
| 48 |
-
frameborder="0">
|
| 49 |
-
</iframe>
|
| 50 |
-
</body>
|
| 51 |
-
</html>
|
| 52 |
-
'''
|
| 53 |
-
return render_template_string(html_content)
|
| 54 |
|
| 55 |
if __name__ == '__main__':
|
| 56 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
+
from flask import Flask, send_file, render_template
|
| 2 |
import requests
|
| 3 |
from io import BytesIO
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
|
| 8 |
+
# Route to serve the PDF in iframe
|
| 9 |
@app.route('/view-pdf')
|
| 10 |
def view_pdf():
|
|
|
|
| 11 |
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'
|
| 12 |
+
|
| 13 |
+
# Modify Dropbox link for direct download
|
| 14 |
if 'dl=0' in link:
|
| 15 |
link = link.replace('dl=0', 'dl=1')
|
| 16 |
|
| 17 |
+
# Download PDF content
|
| 18 |
response = requests.get(link)
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
pdf_path = 'temp_view.pdf'
|
| 21 |
+
with open(pdf_path, 'wb') as f:
|
| 22 |
+
f.write(response.content)
|
| 23 |
+
|
| 24 |
+
# Serve the PDF file
|
| 25 |
+
return send_file(pdf_path, mimetype='application/pdf')
|
| 26 |
+
else:
|
| 27 |
+
return "Failed to download PDF content", 404
|
| 28 |
+
|
| 29 |
+
# Run Flask server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
if __name__ == '__main__':
|
| 32 |
app.run(host='0.0.0.0', port=7860)
|