-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py.py
More file actions
71 lines (36 loc) · 1.02 KB
/
Copy pathapp.py.py
File metadata and controls
71 lines (36 loc) · 1.02 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from flask import Flask, request, jsonify
import pandas as pd
import numpy as np
import joblib
# In[4]:
app = Flask(__name__)
# In[5]:
# Load the trained model
model = joblib.load('fish_species_model.pkl')
# In[6]:
@app.route('/')
def home():
return 'Fish Species Prediction API'
# In[7]:
@app.route('/predict', methods=['POST'])
def predict():
try:
data = request.json
weight = float(data['weight'])
length1 = float(data['length1'])
length2 = float(data['length2'])
length3 = float(data['length3'])
height = float(data['height'])
width = float(data['width'])
input_data = np.array([[weight, length1, length2, length3, height, width]])
prediction = model.predict(input_data)[0]
return jsonify({'species': int(prediction)})
except Exception as e:
return jsonify({'error': str(e)}), 400
# In[ ]:
# In[9]:
get_ipython().system('pip install Flask gunicorn')
# In[ ]: