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