Repository navigation
Expand file tree
/
Copy pathrun.py
More file actions
62 lines (47 loc) · 1.76 KB
/
Copy pathrun.py
File metadata and controls
62 lines (47 loc) · 1.76 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
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2019 - present AppSeed.us
"""
import os
from flask_migrate import Migrate
from flask_minify import Minify
from sys import exit
from apps.config import config_dict
from apps import create_app, db
from flask import request
import numpy as np
from keras.models import load_model
# WARNING: Don't run with debug turned on in production!
DEBUG = (os.getenv('DEBUG', 'False') == 'True')
# The configuration
get_config_mode = 'Debug' if DEBUG else 'Production'
try:
# Load the configuration using the default values
app_config = config_dict[get_config_mode.capitalize()]
except KeyError:
exit('Error: Invalid <config_mode>. Expected values [Debug, Production] ')
app = create_app(app_config)
Migrate(app, db)
if not DEBUG:
Minify(app=app, html=True, js=False, cssless=False)
if DEBUG:
app.logger.info('DEBUG = ' + str(DEBUG) )
app.logger.info('DBMS = ' + app_config.SQLALCHEMY_DATABASE_URI)
app.logger.info('ASSETS_ROOT = ' + app_config.ASSETS_ROOT )
@app.route('/predict')
def predict():
loaded_model = load_model('./model/best_model_site_all.h5')
# Get the three GET arguments
arg1 = float(request.args.get('v'))
arg2 = float(request.args.get('s'))
arg3 = float(request.args.get('w'))
# Assuming your model expects input in the form of a NumPy array
input_data = np.array([[arg1, arg2, arg3]])
reshaped_input = np.tile(input_data, (1, 10, 2)) # Repeat the input along the sequence dimension
# Make predictions using the loaded model
prediction = loaded_model.predict(reshaped_input)
# Assuming your model returns a single value
result = prediction[0][0]
return str(result)
if __name__ == "__main__":
app.run(port="9002")