diff --git a/flaskblog/__init__.py b/flaskblog/__init__.py new file mode 100644 index 0000000..8f40b72 --- /dev/null +++ b/flaskblog/__init__.py @@ -0,0 +1,16 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_bcrypt import Bcrypt +from flask_login import LoginManager +from google.oauth2.credentials import Credentials +from google_auth_oauthlib.flow import Flow + +app = Flask(__name__, template_folder='templates/', static_folder='templates/static/') +app.config['SECRET_KEY']= 'd7ffffeda6d2eee20b6678d783312c7b' +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' +db = SQLAlchemy(app) +bcrypt = Bcrypt(app) +login_manager = LoginManager(app) +# app.config['OPTIONS'] = {'index_files': []} + +from flaskblog import routes \ No newline at end of file diff --git a/flaskblog/__pycache__/__init__.cpython-310.pyc b/flaskblog/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..3010dd2 Binary files /dev/null and b/flaskblog/__pycache__/__init__.cpython-310.pyc differ diff --git a/flaskblog/__pycache__/__init__.cpython-311.pyc b/flaskblog/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..b1e226e Binary files /dev/null and b/flaskblog/__pycache__/__init__.cpython-311.pyc differ diff --git a/flaskblog/__pycache__/forms.cpython-310.pyc b/flaskblog/__pycache__/forms.cpython-310.pyc new file mode 100644 index 0000000..7e8c28c Binary files /dev/null and b/flaskblog/__pycache__/forms.cpython-310.pyc differ diff --git a/flaskblog/__pycache__/forms.cpython-311.pyc b/flaskblog/__pycache__/forms.cpython-311.pyc new file mode 100644 index 0000000..a587316 Binary files /dev/null and b/flaskblog/__pycache__/forms.cpython-311.pyc differ diff --git a/flaskblog/__pycache__/models.cpython-310.pyc b/flaskblog/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..930f441 Binary files /dev/null and b/flaskblog/__pycache__/models.cpython-310.pyc differ diff --git a/flaskblog/__pycache__/models.cpython-311.pyc b/flaskblog/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..3350992 Binary files /dev/null and b/flaskblog/__pycache__/models.cpython-311.pyc differ diff --git a/flaskblog/__pycache__/routes.cpython-310.pyc b/flaskblog/__pycache__/routes.cpython-310.pyc new file mode 100644 index 0000000..629d0e9 Binary files /dev/null and b/flaskblog/__pycache__/routes.cpython-310.pyc differ diff --git a/flaskblog/__pycache__/routes.cpython-311.pyc b/flaskblog/__pycache__/routes.cpython-311.pyc new file mode 100644 index 0000000..2853de4 Binary files /dev/null and b/flaskblog/__pycache__/routes.cpython-311.pyc differ diff --git a/flaskblog/forms.py b/flaskblog/forms.py new file mode 100644 index 0000000..1cfca1e --- /dev/null +++ b/flaskblog/forms.py @@ -0,0 +1,25 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, PasswordField, SubmitField, BooleanField +from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError +from flaskblog.models import User + + +class RegistrationForm(FlaskForm): + email = StringField('Email', + validators=[DataRequired(), Email()]) + password = PasswordField('Password', validators=[DataRequired()]) + confirm_password = PasswordField('Confirm Password', + validators=[DataRequired(), EqualTo('password')]) + submit = SubmitField('Sign Up') + def validate_email(self, email): + + user = User.query.filter_by(email=email.data).first() + if user: + raise ValidationError('That email is already exsist') + +class LoginForm(FlaskForm): + email = StringField('Email', + validators=[DataRequired(), Email()]) + password = PasswordField('Password', validators=[DataRequired()]) + remember = BooleanField('Remember Me') + submit = SubmitField('Login') \ No newline at end of file diff --git a/flaskblog/instance/site.db b/flaskblog/instance/site.db new file mode 100644 index 0000000..cd1954e Binary files /dev/null and b/flaskblog/instance/site.db differ diff --git a/flaskblog/models.py b/flaskblog/models.py new file mode 100644 index 0000000..d9f3645 --- /dev/null +++ b/flaskblog/models.py @@ -0,0 +1,27 @@ +from datetime import datetime +from flaskblog import db, login_manager +from flask_login import UserMixin + +@login_manager.user_loader +def load_user(user_id): + return User.query.get(int(user_id)) + + +class User(db.Model, UserMixin): + id = db.Column(db.Integer, primary_key=True) + email = db.Column(db.String(120), unique=True, nullable=False) + password = db.Column(db.String(60), nullable=False) + posts = db.relationship('Post', backref='author', lazy=True) + + def __repr__(self): + return f"User('{self.email}')" + + +class Post(db.Model): + id = db.Column(db.Integer, primary_key=True) + path = db.Column(db.String(100), nullable=False) + date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) + + def __repr__(self): + return f"Post('{self.path}', '{self.date_posted}')" \ No newline at end of file diff --git a/flaskblog/routes.py b/flaskblog/routes.py new file mode 100644 index 0000000..53e132e --- /dev/null +++ b/flaskblog/routes.py @@ -0,0 +1,114 @@ +from flask import Flask , request, jsonify, render_template , url_for , redirect , flash +from flaskblog import app, db, bcrypt +from flaskblog.forms import RegistrationForm, LoginForm +from flaskblog.models import User, Post +from flask_login import login_user, current_user, logout_user, login_required +import tensorflow as tf +import numpy as np +from PIL import Image, UnidentifiedImageError + + + +# Load the trained model +model = tf.keras.models.load_model('model_2 (3).h5') + +# Define function to preprocess image for model input +def predict_category(file): + categories = ['glioma_tumor', 'meningioma_tumor', 'pituitary_tumor', 'no_tumor'] + img = Image.open(file) + img = img.resize((224, 224)) + + # Convert image to 3-channel format if necessary + if img.mode != 'RGB': + img = img.convert('RGB') + + i = np.array(img, dtype='float32') + i /= 255.0 # normalize image + arr_reshaped = i.reshape((-1, 224, 224, 3)) + output = model.predict(arr_reshaped) + result = categories[np.argmax(output)] + return result + +@app.route('/' , methods=['GET']) +def home(): + return render_template('index.html') + + + +@app.route("/login", methods=['GET', 'POST']) +def login(): + if current_user.is_authenticated: + return redirect(url_for('prediction')) + form = LoginForm() + if form.validate_on_submit(): + user = User.query.filter_by(email=form.email.data).first() + if user and bcrypt.check_password_hash(user.password , form.password.data) : + login_user(user, remember=form.remember.data) + return redirect(url_for('prediction')) + else : + flash('Login Unsuccessful. Please check email and password', 'danger') + return render_template('login.html', title='Login', form=form) + + + +@app.route("/Signup", methods=['GET', 'POST']) +def Signup(): + if current_user.is_authenticated: + return redirect(url_for('prediction')) + form = RegistrationForm() + if form.validate_on_submit(): + hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf_8') + user = User(email=form.email.data, password=hashed_password) + db.session.add(user) + db.session.commit() + #to query all users + # u=User.query.all() + # for uu in u : + # print(uu) + flash(f'Your account has been created! Please login', 'success') + return redirect(url_for('login')) + return render_template('Signup.html', title='Signup', form=form) + + +@app.route("/supervisors") +def super(): + + return render_template('super.html') + + + +@app.route("/logout") +def logout(): + logout_user() + return redirect(url_for('home')) + + + + + + +@app.route('/prediction' , methods=['GET']) +def prediction(): + return render_template('Prediction.html') + + + + + + + +@app.route('/predict', methods=['POST']) +def predict_image(): + # Get image file path from request + file = request.files['image'] + if file.filename == '': + return jsonify({'error': 'No file selected'}) + + + # Make prediction with model + predicted_category = predict_category(file) + # Return predicted category as JSON response + return jsonify({'category': predicted_category}) + + + diff --git a/flaskblog/templates/Prediction.html b/flaskblog/templates/Prediction.html new file mode 100644 index 0000000..cc9e3a9 --- /dev/null +++ b/flaskblog/templates/Prediction.html @@ -0,0 +1,184 @@ + + + +
+ + + + + +Be Verified
+ To be able to use our services . ++ We offer you a chance to improve your diagnosis efficiency by providing that software to help you to + detect Brain Tumors. + All you need to do + + Upload Image . Submit . Get Result +
++
+ + ++
+ + ++ +
++ +
++ +
++ +
++ +
++ +
+Be Verified
+ To be able to use our services . +`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\n\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n\n// Abbreviations\n//\n// 1. Duplicate behavior to the data-bs-* attribute for our tooltip plugin\n// 2. Add the correct text decoration in Chrome, Edge, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Prevent the text-decoration to be skipped.\n\nabbr[title],\nabbr[data-bs-original-title] { // 1\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n text-decoration-skip-ink: none; // 4\n}\n\n\n// Address\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\n\n// Lists\n\nol,\nul {\n padding-left: 2rem;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\n// 1. Undo browser default\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // 1\n}\n\n\n// Blockquote\n\nblockquote {\n margin: 0 0 1rem;\n}\n\n\n// Strong\n//\n// Add the correct font weight in Chrome, Edge, and Safari\n\nb,\nstrong {\n font-weight: $font-weight-bolder;\n}\n\n\n// Small\n//\n// Add the correct font size in all browsers\n\nsmall {\n @include font-size($small-font-size);\n}\n\n\n// Mark\n\nmark {\n padding: $mark-padding;\n background-color: $mark-bg;\n}\n\n\n// Sub and Sup\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n\nsub,\nsup {\n position: relative;\n @include font-size($sub-sup-font-size);\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n// Links\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n\n &:hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([class]) {\n &,\n &:hover {\n color: inherit;\n text-decoration: none;\n }\n}\n\n\n// Code\n\npre,\ncode,\nkbd,\nsamp {\n font-family: $font-family-code;\n @include font-size(1em); // Correct the odd `em` font sizing in all browsers.\n direction: ltr #{\"/* rtl:ignore */\"};\n unicode-bidi: bidi-override;\n}\n\n// 1. Remove browser default top margin\n// 2. Reset browser default of `1em` to use `rem`s\n// 3. Don't allow content to break outside\n\npre {\n display: block;\n margin-top: 0; // 1\n margin-bottom: 1rem; // 2\n overflow: auto; // 3\n @include font-size($code-font-size);\n color: $pre-color;\n\n // Account for some code outputs that place code tags in pre tags\n code {\n @include font-size(inherit);\n color: inherit;\n word-break: normal;\n }\n}\n\ncode {\n @include font-size($code-font-size);\n color: $code-color;\n word-wrap: break-word;\n\n // Streamline the style when inside anchors to avoid broken underline and more\n a > & {\n color: inherit;\n }\n}\n\nkbd {\n padding: $kbd-padding-y $kbd-padding-x;\n @include font-size($kbd-font-size);\n color: $kbd-color;\n background-color: $kbd-bg;\n @include border-radius($border-radius-sm);\n\n kbd {\n padding: 0;\n @include font-size(1em);\n font-weight: $nested-kbd-font-weight;\n }\n}\n\n\n// Figures\n//\n// Apply a consistent margin strategy (matches our type styles).\n\nfigure {\n margin: 0 0 1rem;\n}\n\n\n// Images and content\n\nimg,\nsvg {\n vertical-align: middle;\n}\n\n\n// Tables\n//\n// Prevent double borders\n\ntable {\n caption-side: bottom;\n border-collapse: collapse;\n}\n\ncaption {\n padding-top: $table-cell-padding-y;\n padding-bottom: $table-cell-padding-y;\n color: $table-caption-color;\n text-align: left;\n}\n\n// 1. Removes font-weight bold by inheriting\n// 2. Matches default `