-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
80 lines (60 loc) · 2.48 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from flask import Flask, render_template, request, url_for, send_file, flash, redirect, make_response
import pickle
import numpy as np
import os
import termcolor
import smtplib
# import warnings
import CancerModel
import PdfConverter
from PdfConverter import PDFPageCountError
app = Flask(__name__)
app.config['SECRET_KEY'] = '73a4b6ca8cb647a20b71423e31492452'
@app.route("/infected")
def Infected():
return render_template("Infected.htm", disease="Nothing")
@app.route("/noninfected")
def NonInfected():
return render_template("NonInfected.htm")
@app.route("/download")
def Download():
file = "static/Example.docx"
return send_file(file, as_attachment=True)
@app.route("/", methods=["POST", "GET"])
def BreastCancer():
if request.method == "POST":
f = request.files['inputFile']
name, extension = os.path.splitext(f.filename)
print(extension)
try:
if extension == ".png" or extension == ".jpg" or extension == ".jpeg" or extension == ".pdf":
location = os.path.join("Received_Files", f.filename)
f.save(location)
print("File Saved !")
PDFFilename = f.filename
if extension == ".pdf":
PdfConverter.Convert(f.filename)
image = name + ".png"
prediction = CancerModel.Predict(
os.path.join("Received_Files", image))
else:
prediction = CancerModel.Predict(
os.path.join("Received_Files", f.filename))
for root, dirs, files in os.walk("Received_Files"):
for file in files:
os.remove(os.path.join(root, file))
print(prediction)
if prediction:
return render_template("Infected.htm", disease="Breast Cancer ")
else:
return render_template("NonInfected.htm")
else:
flash(
"Please upload files with extension 'png', 'pdf' , 'jpg' or 'jpeg'")
except ValueError:
flash("Please Upload Only Valid Files ")
except PDFPageCountError:
flash("Please Upload Only Valid Files , or try again later")
return render_template("BreastCancer.html", title="Breast Cancer", navTitle="Breast Cancer", headText="Breast Cancer Early Detection", ImagePath="/static/BreastCancer.jpg")
if __name__ == '__main__':
app.run()