prediction / app.py
fahadcr14
final
d6396d6
from flask import Flask, request, render_template
import numpy as np
import pickle
app = Flask(__name__)
# Cloud Computing Weights and Max Marks
cc_weights = {
'A1': 1, 'Q1': 1.5, 'A2': 1, 'Q2': 1.5, 'A3': 1,
'A4': 4, 'Q3': 1.5, 'Mid': 35, 'AWS Labs': 3,
'Q4': 1.25, 'A5': 4, 'Q5': 1.25, 'A6': 4, 'Final': 40
}
cc_max_marks = {
'A1': 10, 'Q1': 21, 'A2': 10, 'Q2': 30, 'A3': 100,
'A4': 10, 'Q3': 41, 'Mid': 35, 'AWS Labs': 10,
'Q4': 40, 'A5': 100, 'Q5': 20, 'A6': 100, 'Final': 40
}
# ICT Weights and Max Marks
ict_weights = {
'Q1': 2.625, 'Q2': 2.625, 'A1': 2, 'Q3': 2.625, 'Q4': 2.625,
'Midterm': 35, 'Q5': 2.625, 'A2': 2, 'Q6': 2.625, 'Q7': 2.625,
'Q8': 2.625, 'Final': 40
}
ict_max_marks = {
'Q1': 30, 'Q2': 49, 'A1': 100, 'Q3': 30, 'Q4': 15,
'Midterm': 35, 'Q5': 45, 'A2': 100, 'Q6': 32, 'Q7': 24,
'Q8': 40, 'Final': 100
}
def normalize_input(input_activities, weights, max_marks):
"""
Normalize the input activities based on weights and max marks.
"""
normalized_activities = []
for activity, score in input_activities.items():
if score > 0: # Ignore zeros
normalized_score = (score / max_marks[activity]) * weights[activity]
normalized_activities.append(normalized_score)
return normalized_activities
def predict_final_score(input_activities, weights, max_marks, model_prefix):
"""
Predict the final score based on input activities after normalization.
"""
normalized_activities = normalize_input(input_activities, weights, max_marks)
n = len(normalized_activities)
if n == 0:
return "No valid activities entered. Please provide scores greater than 0."
try:
with open(f"{model_prefix}_model_{n}_activities.pkl", "rb") as file:
model = pickle.load(file)
except FileNotFoundError:
return f"No model available for {n} activities. Train the model first."
input_array = np.array(normalized_activities).reshape(1, -1)
predicted_score = model.predict(input_array)[0]
return round(predicted_score, 2)
@app.route('/', methods=['GET', 'POST'])
def home():
cc_predicted_score = None
ict_predicted_score = None
if request.method == 'POST':
# Identify the form (Cloud Computing or ICT)
form_type = request.form.get('form_type')
if form_type == 'cloud_computing':
input_activities = {
activity: float(request.form.get(activity, 0) or 0) # Default to 0 for empty inputs
for activity in cc_weights.keys()
}
cc_predicted_score = predict_final_score(input_activities, cc_weights, cc_max_marks, "cloud_computing")
elif form_type == 'ict':
input_activities = {
activity: float(request.form.get(activity, 0) or 0) # Default to 0 for empty inputs
for activity in ict_weights.keys()
}
ict_predicted_score = predict_final_score(input_activities, ict_weights, ict_max_marks, "ict")
return render_template(
'index.html',
cc_max_marks=cc_max_marks,
ict_max_marks=ict_max_marks,
cc_predicted_score=cc_predicted_score,
ict_predicted_score=ict_predicted_score
)
if __name__ == '__main__':
app.run(debug=False, port=5000)