Spaces:
Runtime error
Runtime error
File size: 1,546 Bytes
51c06eb |
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 |
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)
|