-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (38 loc) · 1.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Flask, request, jsonify
import torch
from flask_cors import CORS
from ultralytics import YOLO
import os
app = Flask(__name__)
CORS(app) # Enable CORS for all domains on all routes
# Load your custom model
model = YOLO('V4.pt')
@app.route('/analyze', methods=['POST'])
def analyze():
print("Got Request")
print(request)
print()
print(request.headers)
data = request.headers.get('imgurl')
image_url = data
print(image_url)
print()
print()
result = model(image_url)[0]
try:
localPath = image_url.split("/")[-1]
os.remove(localPath)
except:
print("Didn't delete")
resultJson = {}
print(result.path)
print(result.probs)
if result.probs.top1 == 0:
resultJson["result"] = "fake"
resultJson["confidence"] = str(result.probs.top1conf.item())
else:
resultJson["result"] = "real"
resultJson["confidence"] = str(result.probs.top1conf.item())
return jsonify(resultJson), 200
if __name__ == '__main__':
app.run(debug=True)