Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,41 @@
|
|
| 1 |
-
from flask import Flask
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
app = Flask(__name__)
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.route('/')
|
| 6 |
def hello():
|
| 7 |
-
return "
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
if __name__ == '__main__':
|
| 10 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
+
from flask import Flask, request, send_file
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
import mimetypes
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
+
#########################################
|
| 7 |
+
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
| 8 |
+
def allowed_file(filename):
|
| 9 |
+
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 10 |
+
app = Flask(__name__)
|
| 11 |
+
###########################################
|
| 12 |
+
#############################################
|
| 13 |
@app.route('/')
|
| 14 |
def hello():
|
| 15 |
+
return "This is my python code Adew"
|
| 16 |
+
########################################
|
| 17 |
+
@app.route('/1', methods=['POST'])
|
| 18 |
+
def upload_file():
|
| 19 |
+
if 'image' not in request.files:
|
| 20 |
+
return {"message": "No file part"}, 400
|
| 21 |
+
file = request.files['image']
|
| 22 |
+
if file.filename == '':
|
| 23 |
+
return {"message": "No selected file"}, 400
|
| 24 |
+
|
| 25 |
+
# send file with angles on image or just angles
|
| 26 |
+
if file and allowed_file(file.filename):
|
| 27 |
+
try:
|
| 28 |
+
file.seek(0)
|
| 29 |
+
mime_type, _ = mimetypes.guess_type(file.filename)
|
| 30 |
+
|
| 31 |
+
return send_file(
|
| 32 |
+
BytesIO(file.read()), mimetype=mime_type,
|
| 33 |
+
as_attachment=False, download_name=file.filename
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return {"message": f"Error processing file: {str(e)}"}, 500
|
| 38 |
+
return {"message": "File not allowed"}, 400
|
| 39 |
+
#####################################
|
| 40 |
if __name__ == '__main__':
|
| 41 |
app.run(host='0.0.0.0', port=7860)
|