Skip to content

Commit

Permalink
WEBSITE
Browse files Browse the repository at this point in the history
  • Loading branch information
marwansss authored Aug 18, 2023
1 parent 9c9aaae commit 61f737d
Show file tree
Hide file tree
Showing 99 changed files with 60,724 additions and 0 deletions.
16 changes: 16 additions & 0 deletions flaskblog/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added flaskblog/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/forms.cpython-310.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/routes.cpython-310.pyc
Binary file not shown.
Binary file added flaskblog/__pycache__/routes.cpython-311.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions flaskblog/forms.py
Original file line number Diff line number Diff line change
@@ -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')
Binary file added flaskblog/instance/site.db
Binary file not shown.
27 changes: 27 additions & 0 deletions flaskblog/models.py
Original file line number Diff line number Diff line change
@@ -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}')"
114 changes: 114 additions & 0 deletions flaskblog/routes.py
Original file line number Diff line number Diff line change
@@ -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})



184 changes: 184 additions & 0 deletions flaskblog/templates/Prediction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="static/style.css">
<title>RadioShash</title>
<script src="{{ url_for('static', filename='js/particles.min.js') }}"></script>
<link rel="icon" href="static/img/5801748.jpg " height="35px" width="40px" class="rounded-circle">
<script>
var message = "right click is disabled";

function rtclickcheck(keyp) {
if (navigator.appName == "Netscape" && keyp.which == 3) {
alert(message);
return false;
}
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {
alert(message);
return false;
}
}

document.onmousedown = rtclickcheck;
</script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Capture form submission event
$('form').submit(function(event) {
event.preventDefault(); // Prevent default form submission behavior

// Create FormData object to capture form data
var formData = new FormData(this);

// Make AJAX request to /predict endpoint
$.ajax({
url: '/predict',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
// Update the predicted category in the <div> element
$('#predicted-category').html('<h2>Result: ' + response.category + '</h2>');
},
error: function() {
console.log('Error occurred during prediction request.');
}
});
});
});
</script>
</head>

<body>
<!-- navbar -->
<nav class="navbar navbar-expand-lg bg-dark navbar-dark fixed-top">
<div class="container">
<!-- <a href="Prediction.html" class="navbar-brand">RadioShash_WebSite</a> -->
<a href="{{ url_for('home') }}" class="navbar-brand"><img src="static/img/5801748.jpg" alt="" height="35px" width="40px" class="rounded-circle">RadioShash</a>
<button class="navbar-toggler" type="button"data-bs-toggle="collapse"data-bs-target="#navmenu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navmenu">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a href="{{ url_for('home') }}" class="nav-link">Home</a>
</li>
<li class="nav-item">
<!-- <a href="index.html" class="nav-link">Logout</a> -->
<a href="{{ url_for('logout') }}" class="nav-link">Logout</a>
</li>
</ul>
</div>
</div>
</nav>



<section id="particles-js" class=" bg-dark vh-50">



<!-- AI model -->
<main>
<h2 class="my py-5 my-5">Upload Image</h2>
<form action="/predict" method="POST" enctype="multipart/form-data" class="p-3 text-center">
<input class="form-control" type="file" name="image">
<br><br>
<input class="btn btn-primary mt-3" type="submit" value="Submit">
</form>
<div id="predicted-category" style="color: grey;">
{% if category %}
<h2>Your Result is: {{ category }}</h2>
{% endif %}
</div>


<div id="predicted-category" style="color: grey;">
{% if error %}
<h2> {{ error }}</h2>
{% endif %}
</div>
</main>







</section>





<!-- footer -->
<footer class="p-5 bg-dark text-white text-center position-relative">
<div class="container">
<p class="leadd">Copy &copy; RadioShash</p>

<a href="#" class="position-absolute bottom-0 end-0 p-5">
<i class="bi bi-arrow-up-circle h1"></i>
</a>
</div>
</footer>




<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
</script> -->

<script src="static/js/bootstrap.min.js"></script>



<script>
particlesJS.load('particles-js', "{{ url_for('static', filename='js/particles.json') }}");
</script>

<script>
var navbar = document.querySelector('.navbar');
var body = document.querySelector('body');
var lastScroll = 0;

window.addEventListener('scroll', function() {
var currentScroll = window.pageYOffset || document.documentElement.scrollTop;
var bodyColor = window.getComputedStyle(body).backgroundColor;

if (currentScroll > lastScroll) {
navbar.style.backgroundColor = bodyColor;
} else {
navbar.style.backgroundColor = 'transparent';
}

if (currentScroll > 0) {
navbar.classList.add('navbar-scrolled');
} else {
navbar.classList.remove('navbar-scrolled');
}

lastScroll = currentScroll;
});






</script>

</body>

</html>



Loading

0 comments on commit 61f737d

Please sign in to comment.