Пример #1
0
def classify_file():
    if request.method == "POST":
        if request.files:
            file = request.files["file"]
            if (file.mimetype).split('/')[0] == 'image':
                file = request.files['file']
                try:
                    img = Image.open(file).convert('RGB')
                    c = img2out(img, app.predictor)
                except PIL.UnidentifiedImageError:
                    c = 'Please check if the uploaded file a valid image/video format'        
            elif (file.mimetype).split('/')[0] == 'video':                
                try:
                    file.save('tmp.mp4')
                    video = cv2.VideoCapture('tmp.mp4')
                    c = vid2out(video, app.predictor)  
                    os.remove('tmp.mp4')
                except:
                    c = 'Please check if the uploaded file a valid image/video format'
    elif request.method == "GET":
        return redirect('deepfakedetection.html')
    try:
        return render_template("deepfakedetection.html", pred_from_file=c)
    except UnboundLocalError:
        c = 'Please check if the uploaded file a valid image/video format'
        return render_template("deepfakedetection.html", pred_from_file=c)
Пример #2
0
def classify_url():
    if request.method == "POST":
        if request.form:
            url = request.form['url']
            if mimetypes.guess_type(url)[0]:
                if mimetypes.guess_type(url)[0].split('/')[0] == 'image':
                    response = requests.get(url)
                    try:
                        img = Image.open(BytesIO(response.content))
                        c = img2out(img, app.predictor)
                    except PIL.UnidentifiedImageError:
                        c = 'Please check if the URL is valid'
            elif not mimetypes.guess_type(url)[0]:
                try: 
                    video = pafy.new(url)
                    best = video.getbest(preftype="mp4")
                    video = cv2.VideoCapture()
                    video.open(best.url)
                    c = vid2out(video, app.predictor)
                except ValueError:
                    c = 'Please check if the URL is valid'
    elif request.method == "GET":
        return redirect('deepfakedetection.html')
    return render_template("deepfakedetection.html", pred_from_url=c)