ehsanhon commited on
Commit
d54c979
·
verified ·
1 Parent(s): 1b13910

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -35
app.py CHANGED
@@ -1,42 +1,10 @@
1
- from flask import Flask, request, send_file
2
- from io import BytesIO
3
- import mimetypes
4
-
5
- def allowed_file(filename):
6
- return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
7
 
8
  app = Flask(__name__)
9
 
10
- ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
11
-
12
-
13
  @app.route('/')
14
  def hello():
15
- return "Hello, Hugging Face!"
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
 
41
  if __name__ == '__main__':
42
- app.run(debug=True)
 
1
+ from flask import Flask
 
 
 
 
 
2
 
3
  app = Flask(__name__)
4
 
 
 
 
5
  @app.route('/')
6
  def hello():
7
+ return "Hello from Hugging Face Docker Space!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  if __name__ == '__main__':
10
+ app.run(host='0.0.0.0', port=7860)