Sergey Mikhno
commited on
Commit
·
decd734
1
Parent(s):
32bc001
spaces
Browse files- app/app.py +12 -8
- app/requirements.txt +2 -1
app/app.py
CHANGED
@@ -22,6 +22,17 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
22 |
def allowed_file(filename):
|
23 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
@app.route("/", methods=['GET', 'POST'])
|
27 |
def doc_layout():
|
@@ -36,14 +47,7 @@ def doc_layout():
|
|
36 |
if file and allowed_file(file.filename):
|
37 |
filename = "/tmp/" + secure_filename(file.filename)
|
38 |
file.save(filename)
|
39 |
-
|
40 |
-
print(device)
|
41 |
-
det_res = model.predict(
|
42 |
-
filename, # Image to predict
|
43 |
-
imgsz=1024, # Prediction image size
|
44 |
-
conf=0.2, # Confidence threshold
|
45 |
-
device=device
|
46 |
-
)
|
47 |
names = det_res[0].names
|
48 |
blocknames = [names[int(n)] for n in det_res[0].boxes.cls]
|
49 |
xyxy = [a.tolist() for a in det_res[0].boxes.xyxy]
|
|
|
22 |
def allowed_file(filename):
|
23 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
24 |
|
25 |
+
@spaces.GPU
|
26 |
+
def predict(filename):
|
27 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
28 |
+
return model.predict(
|
29 |
+
filename, # Image to predict
|
30 |
+
imgsz=1024, # Prediction image size
|
31 |
+
conf=0.2, # Confidence threshold
|
32 |
+
device=device
|
33 |
+
)
|
34 |
+
|
35 |
+
|
36 |
|
37 |
@app.route("/", methods=['GET', 'POST'])
|
38 |
def doc_layout():
|
|
|
47 |
if file and allowed_file(file.filename):
|
48 |
filename = "/tmp/" + secure_filename(file.filename)
|
49 |
file.save(filename)
|
50 |
+
det_res = predict(filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
names = det_res[0].names
|
52 |
blocknames = [names[int(n)] for n in det_res[0].boxes.cls]
|
53 |
xyxy = [a.tolist() for a in det_res[0].boxes.xyxy]
|
app/requirements.txt
CHANGED
@@ -3,5 +3,6 @@ flask == 3.1.1
|
|
3 |
huggingface-hub == 0.33.0
|
4 |
gunicorn
|
5 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
6 |
-
torch
|
|
|
7 |
|
|
|
3 |
huggingface-hub == 0.33.0
|
4 |
gunicorn
|
5 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
6 |
+
torch
|
7 |
+
spaces
|
8 |
|