import gradio as gr from flask import Flask, render_template, request import joblib import numpy as np import pickle app = Flask(__name__) # Load models regressor = joblib.load('model/regressor_model.pkl') classifier = joblib.load('model/classifier_model.pkl') @app.route('/') def home(): return render_template('index.html') @app.route('/regression') def regression(): return render_template('regression.html') @app.route('/classification') def classification(): return render_template('classification.html') @app.route('/predict_regression', methods=['POST']) def predict_regression(): try: input_data = [float(x) for x in request.form.values()] features = np.array([input_data]) prediction = regressor.predict(features)[0] return render_template('regression.html', prediction_text=f'📈 Predicted Value: {prediction:.2f}') except Exception as e: return render_template('regression.html', prediction_text=f"⚠️ Error: {str(e)}") @app.route('/predict_classification', methods=['POST']) def predict_classification(): try: input_data = [float(x) for x in request.form.values()] features = np.array([input_data]) prediction = classifier.predict(features)[0] return render_template('classification.html', prediction_text=f'🎯 Predicted Class: {int(prediction)}') except Exception as e: return render_template('classification.html', prediction_text=f"⚠️ Error: {str(e)}") if __name__ == '__main__': app.run(debug=True)