Sergey Mikhno commited on
Commit
1bad634
·
1 Parent(s): 0f146e2
Files changed (3) hide show
  1. app +0 -0
  2. app/app.py +60 -0
  3. app/requirements.txt +6 -0
app DELETED
File without changes
app/app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask
2
+ from doclayout_yolo import YOLOv10
3
+ from huggingface_hub import hf_hub_download
4
+
5
+ import os
6
+ import json
7
+ from flask import Flask, flash, request, redirect, url_for
8
+ from werkzeug.utils import secure_filename
9
+
10
+ UPLOAD_FOLDER = 'upload'
11
+ ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
12
+
13
+ filepath = hf_hub_download(repo_id="juliozhao/DocLayout-YOLO-DocStructBench", filename="doclayout_yolo_docstructbench_imgsz1024.pt")
14
+ model = YOLOv10(filepath)
15
+
16
+ app = Flask(__name__)
17
+ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
18
+
19
+
20
+ def allowed_file(filename):
21
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
22
+
23
+
24
+ @app.route("/", methods=['GET', 'POST'])
25
+ def doc_layout():
26
+ if request.method == 'POST':
27
+ if 'file' not in request.files:
28
+ flash('no file part')
29
+ return redirect(request.url)
30
+ file = request.files['file']
31
+ if file.filename == '':
32
+ flash('No selected file')
33
+ return redirect(request.url)
34
+ if file and allowed_file(file.filename):
35
+ filename = secure_filename(file.filename)
36
+ file.save(filename)
37
+ det_res = model.predict(
38
+ filename, # Image to predict
39
+ imgsz=1024, # Prediction image size
40
+ conf=0.2, # Confidence threshold
41
+ device="cpu" # Device to use (e.g., 'cuda:0' or 'cpu')
42
+ )
43
+ names = det_res[0].names
44
+ blocknames = [names[int(n)] for n in det_res[0].boxes.cls]
45
+ xyxy = [a.tolist() for a in det_res[0].boxes.xyxy]
46
+ res = [{"coords": y, "type": x} for x, y in zip(blocknames, xyxy)]
47
+ return json.dumps(res)
48
+ return '''
49
+ <!doctype html>
50
+ <title>Upload new File</title>
51
+ <h1>Upload new File</h1>
52
+ <form method=post enctype=multipart/form-data>
53
+ <input type=file name=file>
54
+ <input type=submit value=Upload>
55
+ </form>
56
+ '''
57
+
58
+
59
+ if __name__ == "__main__":
60
+ app.run(host='0.0.0.0', port=8080)
app/requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ doclayout-yolo == 0.0.4
2
+ flask == 3.1.1
3
+ huggingface-hub == 0.33.0
4
+ gunicorn
5
+ torch == 2.5.0
6
+